Skip to content

Commit

Permalink
Merge pull request #26 from adoy/fix-precondition-precedence
Browse files Browse the repository at this point in the history
Fix pre-condition precedence of If-None-Match over If-Modified-Since
  • Loading branch information
l0gicgate authored Apr 15, 2019
2 parents 1ebc898 + e56d164 commit 9b9e6c6
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
}
}

// Last-Modified header and conditional GET check
$lastModified = $response->getHeaderLine('Last-Modified');

if ($lastModified) {
if (!is_integer($lastModified)) {
$lastModified = strtotime($lastModified);
}

$ifModifiedSince = $request->getHeaderLine('If-Modified-Since');

if ($ifModifiedSince && $lastModified <= strtotime($ifModifiedSince)) {
return $response->withStatus(304);
}
}

// ETag header and conditional GET check
$etag = $response->getHeader('ETag');
$etag = reset($etag);
Expand All @@ -102,6 +87,22 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
}
}


// Last-Modified header and conditional GET check
$lastModified = $response->getHeaderLine('Last-Modified');

if ($lastModified) {
if (!is_integer($lastModified)) {
$lastModified = strtotime($lastModified);
}

$ifModifiedSince = $request->getHeaderLine('If-Modified-Since');

if ($ifModifiedSince && $lastModified <= strtotime($ifModifiedSince)) {
return $response->withStatus(304);
}
}

return $response;
}
}

0 comments on commit 9b9e6c6

Please sign in to comment.