function Response::isNotModified
Determines if the Response validators (ETag, Last-Modified) match a conditional value specified in the Request.
If the Response is not modified, it sets the status code to 304 and removes the actual content by calling the setNotModified() method.
@final
File
-
vendor/
symfony/ http-foundation/ Response.php, line 1111
Class
- Response
- Response represents an HTTP response.
Namespace
Symfony\Component\HttpFoundationCode
public function isNotModified(Request $request) : bool {
if (!$request->isMethodCacheable()) {
return false;
}
$notModified = false;
$lastModified = $this->headers
->get('Last-Modified');
$modifiedSince = $request->headers
->get('If-Modified-Since');
if (($ifNoneMatchEtags = $request->getETags()) && null !== ($etag = $this->getEtag())) {
if (0 == strncmp($etag, 'W/', 2)) {
$etag = substr($etag, 2);
}
// Use weak comparison as per https://tools.ietf.org/html/rfc7232#section-3.2.
foreach ($ifNoneMatchEtags as $ifNoneMatchEtag) {
if (0 == strncmp($ifNoneMatchEtag, 'W/', 2)) {
$ifNoneMatchEtag = substr($ifNoneMatchEtag, 2);
}
if ($ifNoneMatchEtag === $etag || '*' === $ifNoneMatchEtag) {
$notModified = true;
break;
}
}
}
elseif ($modifiedSince && $lastModified) {
$notModified = strtotime($modifiedSince) >= strtotime($lastModified);
}
if ($notModified) {
$this->setNotModified();
}
return $notModified;
}