Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / EventSubscriber / ResponseGeneratorSubscriber.php
1 <?php
2
3 namespace Drupal\Core\EventSubscriber;
4
5 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
6 use Symfony\Component\HttpKernel\KernelEvents;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9 /**
10  * Response subscriber to add X-Generator header tag.
11  */
12 class ResponseGeneratorSubscriber implements EventSubscriberInterface {
13
14   /**
15    * Sets extra X-Generator header on successful responses.
16    *
17    * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
18    *   The event to process.
19    */
20   public function onRespond(FilterResponseEvent $event) {
21     if (!$event->isMasterRequest()) {
22       return;
23     }
24
25     $response = $event->getResponse();
26
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)');
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function getSubscribedEvents() {
36     $events[KernelEvents::RESPONSE][] = ['onRespond'];
37     return $events;
38   }
39
40 }