8000 [HttpKernel] Fix HttpCache validation HTTP method by tgalopin · Pull Request #19651 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Fix HttpCache validation HTTP method #19651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ protected function validate(Request $request, Response $entry, $catch = false)
$subRequest = clone $request;

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

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

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

// avoid that the backend sends no content
$subRequest->headers->remove('if_modified_since');
AF6D Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,21 @@ public function testValidatesCachedResponsesWithLastModifiedAndNoFreshnessInform
$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()
{
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
Expand Down
0