[HttpKernel] Fix Apache mod_expires Session Cache-Control issue

This commit is contained in:
Peter Bowyer 2019-09-06 09:27:37 +01:00 committed by Fabien Potencier
parent fbeef96d66
commit 9e942768c9
2 changed files with 9 additions and 0 deletions

View File

@ -56,6 +56,7 @@ abstract class AbstractSessionListener implements EventSubscriberInterface
if ($session instanceof Session ? $session->getUsageIndex() !== end($this->sessionUsageStack) : $session->isStarted()) {
$event->getResponse()
->setExpires(new \DateTime())
->setPrivate()
->setMaxAge(0)
->headers->addCacheControlDirective('must-revalidate');

View File

@ -75,6 +75,9 @@ class SessionListenerTest extends TestCase
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
$this->assertTrue($response->headers->has('Expires'));
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
}
public function testSurrogateMasterRequestIsPublic()
@ -104,10 +107,15 @@ class SessionListenerTest extends TestCase
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('30', $response->headers->getCacheControlDirective('max-age'));
$this->assertFalse($response->headers->has('Expires'));
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
$this->assertTrue($response->headers->has('Expires'));
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
}
}