Commit 7bf2a1ae authored by Niklas Fiekas's avatar Niklas Fiekas Committed by Crell
Browse files

Add FinishResponseSubscriber to set extra headers.

Handle finished responses to set the X-UA-Compatible and the Content-language
headers.

This fixes CommonDrupalHTTPRequestTestCase.
parent 60ebceeb
......@@ -21,6 +21,7 @@
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
use Drupal\Core\EventSubscriber\ViewSubscriber;
use Drupal\Core\EventSubscriber\AccessSubscriber;
use Drupal\Core\EventSubscriber\FinishResponseSubscriber;
use Drupal\Core\EventSubscriber\PathSubscriber;
use Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
use Drupal\Core\EventSubscriber\LegacyControllerSubscriber;
......@@ -77,6 +78,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
$this->dispatcher->addSubscriber(new PathSubscriber());
$this->dispatcher->addSubscriber(new LegacyRequestSubscriber());
$this->dispatcher->addSubscriber(new LegacyControllerSubscriber());
$this->dispatcher->addSubscriber(new FinishResponseSubscriber());
$this->dispatcher->addSubscriber(new RequestCloseSubscriber());
// Some other form of error occured that wasn't handled by another kernel
......
<?php
/**
* @file
* Definition of Drupal\Core\EventSubscriber\FinishResponseSubscriber.
*/
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Response subscriber to handle finished responses.
*/
class FinishResponseSubscriber implements EventSubscriberInterface {
/**
* Sets extra headers on successful responses.
*
* @param FilterResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
$response = $event->getResponse();
// Set the X-UA-Compatible HTTP header to force IE to use the most recent
// rendering engine or use Chrome's frame rendering engine if available.
$response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', false);
// Set the Content-language header.
$response->headers->set('Content-language', drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode);
}
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = array('onRespond');
return $events;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment