Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc5ca5f3

Browse files
committed
bug#19651 [HttpKernel] Fix HttpCache validation HTTP method (tgalopin)
This PR was merged into the 2.7 branch.Discussion----------[HttpKernel] Fix HttpCache validation HTTP method| Q | A| ------------- | ---| Branch? | 2.7| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#19582| License | MIT| Doc PR | -Commits-------1a8a8af [HttpKernel] Fix HttpCache validation HTTP method
2 parentsf12d2b7 +1a8a8af commitc5ca5f3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

‎src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ protected function validate(Request $request, Response $entry, $catch = false)
374374
$subRequest =clone$request;
375375

376376
// send no head requests because we want content
377-
$subRequest->setMethod('GET');
377+
if ('HEAD' ===$request->getMethod()) {
378+
$subRequest->setMethod('GET');
379+
}
378380

379381
// add our cached last-modified validator
380382
$subRequest->headers->set('if_modified_since',$entry->headers->get('Last-Modified'));
@@ -435,7 +437,9 @@ protected function fetch(Request $request, $catch = false)
435437
$subRequest =clone$request;
436438

437439
// send no head requests because we want content
438-
$subRequest->setMethod('GET');
440+
if ('HEAD' ===$request->getMethod()) {
441+
$subRequest->setMethod('GET');
442+
}
439443

440444
// avoid that the backend sends no content
441445
$subRequest->headers->remove('if_modified_since');

‎src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,21 @@ public function testValidatesCachedResponsesWithLastModifiedAndNoFreshnessInform
799799
$this->assertTraceNotContains('miss');
800800
}
801801

802+
publicfunctiontestValidatesCachedResponsesUseSameHttpMethod()
803+
{
804+
$test =$this;
805+
806+
$this->setNextResponse(200,array(),'Hello World',function ($request,$response)use ($test) {
807+
$test->assertSame('OPTIONS',$request->getMethod());
808+
});
809+
810+
// build initial request
811+
$this->request('OPTIONS','/');
812+
813+
// build subsequent request
814+
$this->request('OPTIONS','/');
815+
}
816+
802817
publicfunctiontestValidatesCachedResponsesWithETagAndNoFreshnessInformation()
803818
{
804819
$this->setNextResponse(200,array(),'Hello World',function ($request,$response) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp