You are here

protected function FinishResponseSubscriber::isCacheControlCustomized in Drupal 8

Same name and namespace in other branches
  1. 9 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, private'. 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 203

Class

FinishResponseSubscriber
Response subscriber to handle finished responses.

Namespace

Drupal\Core\EventSubscriber

Code

protected function isCacheControlCustomized(Response $response) {
  $cache_control = $response->headers
    ->get('Cache-Control');
  return $cache_control != 'no-cache, private' && $cache_control != 'private, must-revalidate';
}