HowTo: Set up custom response headers on project level

Edit on GitHub

This document shows how to create customer response headers in your Spryker project. As an example, we use a header that allows playing full-screen videos in Chrome.

The purpose of this document is to illustrate the usage of Symfony\Component\HttpFoundation\Response() and ShopApplicationTwigEventSubscriber::createResponse() to create custom headers.

Info

The procedure described in this document is just an example of what you can do with the customer response headers, so you know where to adjust the headers for the other use cases.

Prerequisites

Ensure that you have the following:

  • Up-to-date Spryker installation
  • Browser to test
  • CMS page with the video in your Spryker-based shop

Set up custom response headers

  1. For the video example, change the CmsController of the respective CMS page:
$response = new \Symfony\Component\HttpFoundation\Response();
        $response->headers->set('Feature-Policy', 'fullscreen *');
        $response->setContent(
            $this->renderView($localeCmsPageDataTransfer->getTemplatePath(), $viewData)
        );
        return $response;
  1. Optional: to change the header response globally, edit \SprykerShop\Yves\ShopApplication\Subscriber\ShopApplicationTwigEventSubscriber::createResponse()
$response->headers->set('Feature-Policy', 'fullscreen *');

After this, you can see the video on the full screen.