3 namespace Drupal\Core\EventSubscriber;
5 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
6 use Symfony\Component\HttpKernel\KernelEvents;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10 * Response subscriber to add X-Generator header tag.
12 class ResponseGeneratorSubscriber implements EventSubscriberInterface {
15 * Sets extra X-Generator header on successful responses.
17 * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
18 * The event to process.
20 public function onRespond(FilterResponseEvent $event) {
21 if (!$event->isMasterRequest()) {
25 $response = $event->getResponse();
27 // Set the generator in the HTTP header.
28 list($version) = explode('.', \Drupal::VERSION, 2);
29 $response->headers->set('X-Generator', 'Drupal ' . $version . ' (https://www.drupal.org)');
35 public static function getSubscribedEvents() {
36 $events[KernelEvents::RESPONSE][] = ['onRespond'];