Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e94276

Browse filesBrowse files
pbowyerfabpot
authored andcommitted
[HttpKernel] Fix Apache mod_expires Session Cache-Control issue
1 parent fbeef96 commit 9e94276
Copy full SHA for 9e94276

File tree

2 files changed

+9
-0
lines changed
Filter options

2 files changed

+9
-0
lines changed

‎src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function onKernelResponse(FilterResponseEvent $event)
5656

5757
if ($session instanceof Session ? $session->getUsageIndex() !== end($this->sessionUsageStack) : $session->isStarted()) {
5858
$event->getResponse()
59+
->setExpires(new \DateTime())
5960
->setPrivate()
6061
->setMaxAge(0)
6162
->headers->addCacheControlDirective('must-revalidate');

‎src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public function testResponseIsPrivate()
7575
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
7676
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
7777
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
78+
79+
$this->assertTrue($response->headers->has('Expires'));
80+
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
7881
}
7982

8083
public function testSurrogateMasterRequestIsPublic()
@@ -104,10 +107,15 @@ public function testSurrogateMasterRequestIsPublic()
104107
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
105108
$this->assertSame('30', $response->headers->getCacheControlDirective('max-age'));
106109

110+
$this->assertFalse($response->headers->has('Expires'));
111+
107112
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
108113

109114
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
110115
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
111116
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
117+
118+
$this->assertTrue($response->headers->has('Expires'));
119+
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
112120
}
113121
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.