Skip to content

Commit 1b8687d

Browse files
committed
[HttpKernel] Fix HttpCache validation HTTP method
1 parent addb929 commit 1b8687d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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');

Tests/HttpCache/HttpCacheTest.php

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

777+
public function testValidatesCachedResponsesUseSameHttpMethod()
778+
{
779+
$test = $this;
780+
781+
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($test) {
782+
$test->assertSame('OPTIONS', $request->getMethod());
783+
});
784+
785+
// build initial request
786+
$this->request('OPTIONS', '/');
787+
788+
// build subsequent request
789+
$this->request('OPTIONS', '/');
790+
}
791+
777792
public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
778793
{
779794
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {

0 commit comments

Comments
 (0)