protected function FinishResponseSubscriber::isCacheControlCustomized in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php \Drupal\Core\EventSubscriber\FinishResponseSubscriber::isCacheControlCustomized()
Determine whether the given response has a custom Cache-Control header.
Upon construction, the ResponseHeaderBag is initialized with an empty Cache-Control header. Consequently it is not possible to check whether the header was set explicitly by simply checking its presence. Instead, it is necessary to examine the computed Cache-Control header and compare with values known to be present only when Cache-Control was never set explicitly.
When neither Cache-Control nor any of the ETag, Last-Modified, Expires headers are set on the response, ::get('Cache-Control') returns the value 'no-cache'. If any of ETag, Last-Modified or Expires are set but not Cache-Control, then 'private, must-revalidate' (in exactly this order) is returned.
Parameters
\Symfony\Component\HttpFoundation\Response $response:
Return value
bool TRUE when Cache-Control header was set explicitly on the given response.
See also
\Symfony\Component\HttpFoundation\ResponseHeaderBag::computeCacheControlValue()
1 call to FinishResponseSubscriber::isCacheControlCustomized()
- FinishResponseSubscriber::onRespond in core/
lib/ Drupal/ Core/ EventSubscriber/ FinishResponseSubscriber.php - Sets extra headers on successful responses.
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ FinishResponseSubscriber.php, line 193 - Contains \Drupal\Core\EventSubscriber\FinishResponseSubscriber.
Class
- FinishResponseSubscriber
- Response subscriber to handle finished responses.
Namespace
Drupal\Core\EventSubscriberCode
protected function isCacheControlCustomized(Response $response) {
$cache_control = $response->headers
->get('Cache-Control');
return $cache_control != 'no-cache' && $cache_control != 'private, must-revalidate';
}