function FinishResponseSubscriber::onAllResponds

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php \Drupal\Core\EventSubscriber\FinishResponseSubscriber::onAllResponds()
  2. 8.9.x core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php \Drupal\Core\EventSubscriber\FinishResponseSubscriber::onAllResponds()
  3. 10 core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php \Drupal\Core\EventSubscriber\FinishResponseSubscriber::onAllResponds()

Sets extra headers on any responses, also subrequest ones.

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $event: The event to process.

File

core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php, line 68

Class

FinishResponseSubscriber
Response subscriber to handle finished responses.

Namespace

Drupal\Core\EventSubscriber

Code

public function onAllResponds(ResponseEvent $event) {
  $response = $event->getResponse();
  // Always add the 'http_response' cache tag to be able to invalidate every
  // response, for example after rebuilding routes.
  if ($response instanceof CacheableResponseInterface) {
    $response->getCacheableMetadata()
      ->addCacheTags([
      'http_response',
    ]);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.