diff --git a/src/Cache.php b/src/Cache.php index c488549..6fe9e2f 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -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); @@ -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; } }