class ResponseGeneratorSubscriber in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/ResponseGeneratorSubscriber.php \Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber
Response subscriber to add X-Generator header tag.
Hierarchy
- class \Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ResponseGeneratorSubscriber
1 string reference to 'ResponseGeneratorSubscriber'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ResponseGeneratorSubscriber
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ ResponseGeneratorSubscriber.php, line 12
Namespace
Drupal\Core\EventSubscriberView source
class ResponseGeneratorSubscriber implements EventSubscriberInterface {
/**
* Sets extra X-Generator header on successful responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$response = $event
->getResponse();
// Set the generator in the HTTP header.
list($version) = explode('.', \Drupal::VERSION, 2);
$response->headers
->set('X-Generator', 'Drupal ' . $version . ' (https://www.drupal.org)');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = [
'onRespond',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResponseGeneratorSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ResponseGeneratorSubscriber:: |
public | function | Sets extra X-Generator header on successful responses. |