class ClientErrorResponseSubscriber in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/ClientErrorResponseSubscriber.php \Drupal\Core\EventSubscriber\ClientErrorResponseSubscriber
- 10 core/lib/Drupal/Core/EventSubscriber/ClientErrorResponseSubscriber.php \Drupal\Core\EventSubscriber\ClientErrorResponseSubscriber
Response subscriber to set the '4xx-response' cache tag on 4xx responses.
Hierarchy
- class \Drupal\Core\EventSubscriber\ClientErrorResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ClientErrorResponseSubscriber
1 string reference to 'ClientErrorResponseSubscriber'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ClientErrorResponseSubscriber
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ ClientErrorResponseSubscriber.php, line 14
Namespace
Drupal\Core\EventSubscriberView source
class ClientErrorResponseSubscriber implements EventSubscriberInterface {
/**
* Sets the '4xx-response' cache tag on 4xx responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$response = $event
->getResponse();
if (!$response instanceof CacheableResponseInterface) {
return;
}
if ($response
->isClientError()) {
$http_4xx_response_cacheability = new CacheableMetadata();
$http_4xx_response_cacheability
->setCacheTags([
'4xx-response',
]);
$response
->addCacheableDependency($http_4xx_response_cacheability);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Priority 10, so that it runs before FinishResponseSubscriber, which will
// expose the cacheability metadata in the form of headers.
$events[KernelEvents::RESPONSE][] = [
'onRespond',
10,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientErrorResponseSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ClientErrorResponseSubscriber:: |
public | function | Sets the '4xx-response' cache tag on 4xx responses. |