Skip to content

Commit fcb1536

Browse files
Merge branch '5.4' into 6.0
* 5.4: fix merge [HttpClient] mark test transient [Mime] Fix test [Translation] Fix TranslationPullCommand with ICU translations [PropertyInfo] Fix phpstan extractor issues Allow package-versions-deprecated plugin Update security.lb.xlf [Notifier] Use correct factory for the msteams transport Fix SessionListener without session in request Remove direct dependency on composer/package-versions-deprecated Remove the unused dependency on composer/package-versions-deprecated [Security/Http] Fix cookie clearing on logout [HttpClient] fix checking for recent curl consts
2 parents 64dd750 + 3bfe9cd commit fcb1536

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

EventListener/AbstractSessionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function onKernelRequest(RequestEvent $event)
8888

8989
public function onKernelResponse(ResponseEvent $event)
9090
{
91-
if (!$event->isMainRequest()) {
91+
if (!$event->isMainRequest() || (!$this->container->has('initialized_session') && !$event->getRequest()->hasSession())) {
9292
return;
9393
}
9494

Tests/EventListener/SessionListenerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,24 @@ public function testUninitializedSession()
326326
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
327327
}
328328

329+
public function testUninitializedSessionWithoutInitializedSession()
330+
{
331+
$kernel = $this->createMock(HttpKernelInterface::class);
332+
$response = new Response();
333+
$response->setSharedMaxAge(60);
334+
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
335+
336+
$container = new ServiceLocator([]);
337+
338+
$listener = new SessionListener($container);
339+
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
340+
$this->assertFalse($response->headers->has('Expires'));
341+
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
342+
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
343+
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
344+
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
345+
}
346+
329347
public function testSurrogateMainRequestIsPublic()
330348
{
331349
$session = $this->createMock(Session::class);

0 commit comments

Comments
 (0)