BUGFIX: caching fixes

This commit is contained in:
Jeroen De Meerleer 2022-09-12 15:18:46 +02:00
parent d926191539
commit 38d05749fd
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,37 @@
<?php
namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class CacheHeadersSubscriber implements EventSubscriberInterface
{
private $params;
public function __construct(ContainerBagInterface $params)
{
$this->params = $params;
}
public function onResponse(ResponseEvent $event)
{
$response = $event->getResponse();
$response->headers->addCacheControlDirective('max-age', 900);
$response->headers->addCacheControlDirective('s-maxage', 900);
$response->headers->addCacheControlDirective('must-revalidate', true);
$response->headers->addCacheControlDirective('public', true);
$response->headers->removeCacheControlDirective('private');
$event->setResponse($response);
}
public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => 'onResponse'
];
}
}

2
src/EventSubscriber/SecurityHeadersSubscriber.php Normal file → Executable file
View File

@ -24,6 +24,8 @@ class SecurityHeadersSubscriber implements EventSubscriberInterface
$referer = $securitypolicy['referer_policy']; $referer = $securitypolicy['referer_policy'];
$response->headers->set("Content-Security-Policy", $csp); $response->headers->set("Content-Security-Policy", $csp);
$response->headers->set("Referrer-Policy", $referer); $response->headers->set("Referrer-Policy", $referer);
$event->setResponse($response);
} }
public static function getSubscribedEvents() public static function getSubscribedEvents()