@@ -590,6 +590,30 @@ public function testResponseHeadersMaxAgeAndExpiresDefaultValuesIfSessionStarted
590
590
$ this ->assertFalse ($ response ->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
591
591
}
592
592
593
+ public function testPrivateResponseMaxAgeIsRespectedIfSessionStarted ()
594
+ {
595
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
596
+
597
+ $ session = $ this ->createMock (Session::class);
598
+ $ session ->expects ($ this ->once ())->method ('getUsageIndex ' )->willReturn (1 );
599
+ $ request = new Request ([], [], [], [], [], ['SERVER_PROTOCOL ' => 'HTTP/1.0 ' ]);
600
+ $ request ->setSession ($ session );
601
+
602
+ $ response = new Response ();
603
+ $ response ->headers ->set ('Cache-Control ' , 'no-cache ' );
604
+ $ response ->prepare ($ request );
605
+
606
+ $ listener = new SessionListener (new Container ());
607
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST , $ response ));
608
+
609
+ $ this ->assertSame (0 , $ response ->getMaxAge ());
610
+ $ this ->assertFalse ($ response ->headers ->hasCacheControlDirective ('public ' ));
611
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('private ' ));
612
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('must-revalidate ' ));
613
+ $ this ->assertLessThanOrEqual (new \DateTimeImmutable ('now ' , new \DateTimeZone ('UTC ' )), new \DateTimeImmutable ($ response ->headers ->get ('Expires ' )));
614
+ $ this ->assertFalse ($ response ->headers ->has (AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER ));
615
+ }
616
+
593
617
public function testSurrogateMainRequestIsPublic ()
594
618
{
595
619
$ session = $ this ->createMock (Session::class);
0 commit comments