From 38d05749fd80f3d441b0d14eb99ea3a713b5c739 Mon Sep 17 00:00:00 2001 From: jeroen Date: Mon, 12 Sep 2022 15:18:46 +0200 Subject: [PATCH] BUGFIX: caching fixes --- .../CacheHeadersSubscriber.php | 37 +++++++++++++++++++ .../SecurityHeadersSubscriber.php | 2 + 2 files changed, 39 insertions(+) create mode 100755 src/EventSubscriber/CacheHeadersSubscriber.php mode change 100644 => 100755 src/EventSubscriber/SecurityHeadersSubscriber.php diff --git a/src/EventSubscriber/CacheHeadersSubscriber.php b/src/EventSubscriber/CacheHeadersSubscriber.php new file mode 100755 index 0000000..e407d53 --- /dev/null +++ b/src/EventSubscriber/CacheHeadersSubscriber.php @@ -0,0 +1,37 @@ +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' + ]; + } +} \ No newline at end of file diff --git a/src/EventSubscriber/SecurityHeadersSubscriber.php b/src/EventSubscriber/SecurityHeadersSubscriber.php old mode 100644 new mode 100755 index 9bd80d6..f924a35 --- a/src/EventSubscriber/SecurityHeadersSubscriber.php +++ b/src/EventSubscriber/SecurityHeadersSubscriber.php @@ -24,6 +24,8 @@ class SecurityHeadersSubscriber implements EventSubscriberInterface $referer = $securitypolicy['referer_policy']; $response->headers->set("Content-Security-Policy", $csp); $response->headers->set("Referrer-Policy", $referer); + + $event->setResponse($response); } public static function getSubscribedEvents()