BUGFIX: caching fixes
This commit is contained in:
parent
d926191539
commit
38d05749fd
37
src/EventSubscriber/CacheHeadersSubscriber.php
Executable file
37
src/EventSubscriber/CacheHeadersSubscriber.php
Executable 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
2
src/EventSubscriber/SecurityHeadersSubscriber.php
Normal file → Executable 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user