8000 Response::isNotModified returns true when If-Modified-Since is later than Last-Modified by skolodyazhnyy · Pull Request #11079 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Response::isNotModified returns true when If-Modified-Since is later than Last-Modified #11079

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Response::isNotModified returns true when If-Modified-Since is later …
…than Last-Modified
  • Loading branch information
skolodyazhnyy committed Jun 18, 2014
commit 21f904352d72a2a28928b293aeccdfe5bb497450
14 changes: 9 additions & 5 deletions src/Symfony/Component/HttpFoundation/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,16 @@ public function isNotModified(Request $request)
return false;
}

$lastModified = $request->headers->get('If-Modified-Since');
$notModified = false;
$notModified = false;
$lastModified = $this->headers->get('Last-Modified');
$modifiedSince = $request->headers->get('If-Modified-Since');

if ($etags = $request->getEtags()) {
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
} elseif ($lastModified) {
$notModified = $lastModified == $this->headers->get('Last-Modified');
$notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
}

if ($modifiedSince && $lastModified) {
$notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
}

if ($notModified) {
Expand Down
35 changes: 35 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,25 @@ public function testIsNotModifiedNotSafe()

public function testIsNotModifiedLastModified()
{
$before = 'Sun, 25 Aug 2013 18:32:31 GMT';
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
$after = 'Sun, 25 Aug 2013 19:33:31 GMT';

$request = new Request();
$request->headers->set('If-Modified-Since', $modified);

$response = new Response();
$response->headers->set('Last-Modified', $modified);

$response->headers->set('Last-Modified', $modified);
$this->assertTrue($response->isNotModified($request));

$response->headers->set('Last-Modified', $before);
$this->assertTrue($response->isNotModified($request));

$response->headers->set('Last-Modified', $after);
$this->assertFalse($response->isNotModified($request));

$response->headers->set('Last-Modified', '');
$this->assertFalse($response->isNotModified($request));
}
Expand All @@ -175,6 +184,32 @@ public function testIsNotModifiedEtag()
$this->assertFalse($response->isNotModified($request));
}

public function testIsNotModifiedLastModifiedAndEtag()
{
$before = 'Sun, 25 Aug 2013 18:32:31 GMT';
$modified = 'Sun, 25 Aug 2013 18:33:31 GMT';
$after = 'Sun, 25 Aug 2013 19:33:31 GMT';
$etag = 'randomly_generated_etag';

$request = new Request();
$request->headers->set('if_none_match', sprintf('%s, %s', $etag, 'etagThree'));
$request->headers->set('If-Modified-Since', $modified);

$response = new Response();

$response->headers->set('ETag', $etag);
$response->headers->set('Last-Modified', $after);
$this->assertFalse($response->isNotModified($request));

$response->headers->set('ETag', 'non-existent-etag');
$response->headers->set('Last-Modified', $before);
$this->assertFalse($response->isNotModified($request));

$response->headers->set('ETag', $etag);
$response->headers->set('Last-Modified', $modified);
$this->assertTrue($response->isNotModified($request));
}

public function testIsValidateable()
{
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
Expand Down
0