class ResponseGeneratorSubscriber

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/ResponseGeneratorSubscriber.php \Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber
  2. 8.9.x core/lib/Drupal/Core/EventSubscriber/ResponseGeneratorSubscriber.php \Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber
  3. 10 core/lib/Drupal/Core/EventSubscriber/ResponseGeneratorSubscriber.php \Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber

Response subscriber to add X-Generator header tag.

Hierarchy

Expanded class hierarchy of ResponseGeneratorSubscriber

File

core/lib/Drupal/Core/EventSubscriber/ResponseGeneratorSubscriber.php, line 12

Namespace

Drupal\Core\EventSubscriber
View source
class ResponseGeneratorSubscriber implements EventSubscriberInterface {
    
    /**
     * Sets extra X-Generator header on successful responses.
     *
     * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
     *   The event to process.
     */
    public function onRespond(ResponseEvent $event) {
        if (!$event->isMainRequest()) {
            return;
        }
        $response = $event->getResponse();
        // Set the generator in the HTTP header.
        [
            $version,
        ] = explode('.', \Drupal::VERSION, 2);
        $response->headers
            ->set('X-Generator', 'Drupal ' . $version . ' (https://www.drupal.org)');
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        $events[KernelEvents::RESPONSE][] = [
            'onRespond',
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ResponseGeneratorSubscriber::getSubscribedEvents public static function
ResponseGeneratorSubscriber::onRespond public function Sets extra X-Generator header on successful responses.

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