vendor/shopware/core/Framework/Api/EventListener/ResponseHeaderListener.php line 25

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\EventListener;
  3. use Shopware\Core\PlatformRequest;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class ResponseHeaderListener implements EventSubscriberInterface
  8. {
  9.     private const HEADERS = [
  10.         PlatformRequest::HEADER_VERSION_ID,
  11.         PlatformRequest::HEADER_LANGUAGE_ID,
  12.         PlatformRequest::HEADER_CONTEXT_TOKEN,
  13.     ];
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             KernelEvents::RESPONSE => 'onResponse',
  18.         ];
  19.     }
  20.     public function onResponse(ResponseEvent $event): void
  21.     {
  22.         $headersBag $event->getResponse()->headers;
  23.         foreach (self::HEADERS as $header) {
  24.             $headersBag->set(
  25.                 $header,
  26.                 $event->getRequest()->headers->get($header),
  27.                 false
  28.             );
  29.         }
  30.         if (!$headersBag->has(PlatformRequest::HEADER_FRAME_OPTIONS)) {
  31.             $headersBag->set(
  32.                 PlatformRequest::HEADER_FRAME_OPTIONS,
  33.                 'deny',
  34.                 false
  35.             );
  36.         }
  37.     }
  38. }