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
This commit is contained in:
commit
c5ca5f3ed7
@ -374,7 +374,9 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
|||||||
$subRequest = clone $request;
|
$subRequest = clone $request;
|
||||||
|
|
||||||
// send no head requests because we want content
|
// send no head requests because we want content
|
||||||
|
if ('HEAD' === $request->getMethod()) {
|
||||||
$subRequest->setMethod('GET');
|
$subRequest->setMethod('GET');
|
||||||
|
}
|
||||||
|
|
||||||
// add our cached last-modified validator
|
// add our cached last-modified validator
|
||||||
$subRequest->headers->set('if_modified_since', $entry->headers->get('Last-Modified'));
|
$subRequest->headers->set('if_modified_since', $entry->headers->get('Last-Modified'));
|
||||||
@ -435,7 +437,9 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
|||||||
$subRequest = clone $request;
|
$subRequest = clone $request;
|
||||||
|
|
||||||
// send no head requests because we want content
|
// send no head requests because we want content
|
||||||
|
if ('HEAD' === $request->getMethod()) {
|
||||||
$subRequest->setMethod('GET');
|
$subRequest->setMethod('GET');
|
||||||
|
}
|
||||||
|
|
||||||
// avoid that the backend sends no content
|
// avoid that the backend sends no content
|
||||||
$subRequest->headers->remove('if_modified_since');
|
$subRequest->headers->remove('if_modified_since');
|
||||||
|
@ -799,6 +799,21 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
$this->assertTraceNotContains('miss');
|
$this->assertTraceNotContains('miss');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidatesCachedResponsesUseSameHttpMethod()
|
||||||
|
{
|
||||||
|
$test = $this;
|
||||||
|
|
||||||
|
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($test) {
|
||||||
|
$test->assertSame('OPTIONS', $request->getMethod());
|
||||||
|
});
|
||||||
|
|
||||||
|
// build initial request
|
||||||
|
$this->request('OPTIONS', '/');
|
||||||
|
|
||||||
|
// build subsequent request
|
||||||
|
$this->request('OPTIONS', '/');
|
||||||
|
}
|
||||||
|
|
||||||
public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
|
public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
|
||||||
{
|
{
|
||||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||||
|
Reference in New Issue
Block a user