File tree 3 files changed +22
-5
lines changed
HttpFoundation/Session/Storage 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -389,6 +389,9 @@ public function setOptions(array $options)
389
389
$ this ->emulateSameSite = $ value ;
390
390
continue ;
391
391
}
392
+ if ('cookie_secure ' === $ key && 'auto ' === $ value ) {
393
+ continue ;
394
+ }
392
395
ini_set ('url_rewriter.tags ' !== $ key ? 'session. ' .$ key : $ key , $ value );
393
396
}
394
397
}
Original file line number Diff line number Diff line change 14
14
use Psr \Container \ContainerInterface ;
15
15
use Symfony \Component \HttpFoundation \Session \SessionInterface ;
16
16
use Symfony \Component \HttpFoundation \Session \Storage \NativeSessionStorage ;
17
+ use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
17
18
18
19
/**
19
20
* Sets the session in the request.
@@ -33,10 +34,12 @@ public function __construct(ContainerInterface $container)
33
34
$ this ->container = $ container ;
34
35
}
35
36
36
- protected function getSession (): ? SessionInterface
37
+ public function onKernelRequest ( GetResponseEvent $ event )
37
38
{
38
- if (!$ this ->container ->has ('session ' )) {
39
- return null ;
39
+ parent ::onKernelRequest ($ event );
40
+
41
+ if (!$ event ->isMasterRequest () || !$ this ->container ->has ('session ' )) {
42
+ return ;
40
43
}
41
44
42
45
if ($ this ->container ->has ('session_storage ' )
@@ -46,6 +49,13 @@ protected function getSession(): ?SessionInterface
46
49
) {
47
50
$ storage ->setOptions (['cookie_secure ' => true ]);
48
51
}
52
+ }
53
+
54
+ protected function getSession (): ?SessionInterface
55
+ {
56
+ if (!$ this ->container ->has ('session ' )) {
57
+ return null ;
58
+ }
49
59
50
60
return $ this ->container ->get ('session ' );
51
61
}
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ public function testSessionIsSet()
59
59
$ listener = new SessionListener ($ container );
60
60
61
61
$ event = $ this ->createMock (RequestEvent::class);
62
- $ event ->expects ($ this ->once ( ))->method ('isMasterRequest ' )->willReturn (true );
62
+ $ event ->expects ($ this ->exactly ( 2 ))->method ('isMasterRequest ' )->willReturn (true );
63
63
$ event ->expects ($ this ->once ())->method ('getRequest ' )->willReturn ($ request );
64
64
65
65
$ listener ->onKernelRequest ($ event );
@@ -203,12 +203,16 @@ public function testGetSessionIsCalledOnce()
203
203
$ listener = new SessionListener ($ container );
204
204
$ listener ->onKernelRequest ($ event );
205
205
206
+ // storage->setOptions() should have been called already
207
+ $ container ->set ('session_storage ' , null );
208
+ $ sessionStorage = null ;
209
+
206
210
$ subRequest = $ masterRequest ->duplicate ();
207
211
// at this point both master and subrequest have a closure to build the session
208
212
209
213
$ masterRequest ->getSession ();
210
214
211
- // calling the factory on the subRequest should not trigger a second call to storage->sesOptions ()
215
+ // calling the factory on the subRequest should not trigger a second call to storage->setOptions ()
212
216
$ subRequest ->getSession ();
213
217
}
214
218
}
You can’t perform that action at this time.
0 commit comments