HowTo - Set up custom response headers on project level

Edit on GitHub

This HowTo will teach you how to create customer response headers in your Spryker project. We use a header that allows playing full-screen videos in Chrome is used as an example.

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

Info

The procedure described in this HowTo 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:

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

Setting up custom response headers

To 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 *');

You should now be able to see the video on the full screen.