4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\EventListener;
14 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
15 use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
16 use Symfony\Component\HttpKernel\KernelEvents;
17 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
20 * SurrogateListener adds a Surrogate-Control HTTP header when the Response needs to be parsed for Surrogates.
22 * @author Fabien Potencier <fabien@symfony.com>
24 class SurrogateListener implements EventSubscriberInterface
31 * @param SurrogateInterface $surrogate An SurrogateInterface instance
33 public function __construct(SurrogateInterface $surrogate = null)
35 $this->surrogate = $surrogate;
39 * Filters the Response.
41 * @param FilterResponseEvent $event A FilterResponseEvent instance
43 public function onKernelResponse(FilterResponseEvent $event)
45 if (!$event->isMasterRequest() || null === $this->surrogate) {
49 $this->surrogate->addSurrogateControl($event->getResponse());
52 public static function getSubscribedEvents()
55 KernelEvents::RESPONSE => 'onKernelResponse',