Skip to content

Commit c5ca5f3

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 parents f12d2b7 + 1a8a8af commit c5ca5f3

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+
public function testValidatesCachedResponsesUseSameHttpMethod()
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
public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
803818
{
804819
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy