diff --git a/core/lib/Drupal/Core/EventSubscriber/AttachedHeadersSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/AttachedHeadersSubscriber.php index 376786b..421b2df 100644 --- a/core/lib/Drupal/Core/EventSubscriber/AttachedHeadersSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/AttachedHeadersSubscriber.php @@ -28,6 +28,22 @@ class AttachedHeadersSubscriber extends ResponseHeaderBag implements EventSubscriberInterface { /** + * Remove the Cache-Control header from this storage service. + * + * Our superclass adds a Cache-Control header automatically. However, + * FinishResponseSubscriber and others will deal with the Cache-Control + * header for the ResponseHeaderBag being output, and depend on this header + * not being set. + * + * @param array $headers + * (optional) Initial headers. + */ + public function __construct(array $headers = array()) { + parent::__construct($headers); + $this->remove('Cache-Control'); + } + + /** * Add attached headers to the final response object. * * @param Symfony\Component\HttpKernel\Event\FilterResponseEvent $event @@ -38,24 +54,23 @@ public function onRespond(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } - // Gather the response object from the event. $response = $event->getResponse(); - // Add each of our headers to the response object's headers. - foreach ($this->getIterator() as $name => $value) { - // Symfony special-cases the 'Status' header. - if ($name === 'status') { - $response->setStatusCode($value); - } - $response->headers->set($name, $value, FALSE); + // Check for the 'status' special case. + if ($this->has('status')) { + $response->setStatusCode($this->get('status')); + $this->remove('status'); } + $response->headers->add($this->all()); } /** * {@inheritdoc} */ public static function getSubscribedEvents() { - $events[KernelEvents::RESPONSE][] = array('onRespond'); + // Set to low priority so that the render array has the last word on headers + // it specifies. + $events[KernelEvents::RESPONSE][] = array('onRespond', -1000); return $events; } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/AttachedHeadersSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/AttachedHeadersSubscriberTest.php index 42114c5..43896f7 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/AttachedHeadersSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/AttachedHeadersSubscriberTest.php @@ -15,7 +15,7 @@ * @coversDefaultClass \Drupal\Core\EventSubscriber\AttachedHeadersSubscriber * @group EventSubscriber */ -class AttachedHeaderSubscriberTest extends UnitTestCase { +class AttachedHeadersSubscriberTest extends UnitTestCase { public function providerOnRespond() { return [