function ResponseGeneratorSubscriber::onRespond

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

Sets extra X-Generator header on successful responses.

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $event: The event to process.

File

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

Class

ResponseGeneratorSubscriber
Response subscriber to add X-Generator header tag.

Namespace

Drupal\Core\EventSubscriber

Code

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)');
}

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