Skip to content

Commit aeaf090

Browse files
committed
make sure no caching happens when hash mismatch
1 parent bcdecd7 commit aeaf090

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

EventListener/UserContextSubscriber.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ public function onKernelResponse(FilterResponseEvent $event)
166166
if ($request->headers->has($this->hashHeader)) {
167167
// hash has changed, session has most certainly changed, prevent setting incorrect cache
168168
if (!is_null($this->hash) && $this->hash !== $request->headers->get($this->hashHeader)) {
169-
$response->setClientTtl(0);
169+
$response->setCache([
170+
'max_age' => 0,
171+
's_maxage' => 0,
172+
'private' => true,
173+
]);
170174
$response->headers->addCacheControlDirective('no-cache');
175+
$response->headers->addCacheControlDirective('no-store');
171176

172177
return;
173178
}

Tests/Unit/EventListener/UserContextSubscriberTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function testFullRequestHashChanged()
259259
$userContextSubscriber->onKernelResponse($event);
260260

261261
$this->assertFalse($event->getResponse()->headers->has('Vary'));
262-
$this->assertEquals('max-age=0, no-cache, private', $event->getResponse()->headers->get('Cache-Control'));
262+
$this->assertEquals('max-age=0, no-cache, no-store, private, s-maxage=0', $event->getResponse()->headers->get('Cache-Control'));
263263
}
264264

265265
protected function getKernelRequestEvent(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)

0 commit comments

Comments
 (0)