File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,10 @@ def save_session(
329
329
samesite = self .get_cookie_samesite (app )
330
330
httponly = self .get_cookie_httponly (app )
331
331
332
+ # Add a "Vary: Cookie" header if the session was accessed at all.
333
+ if session .accessed :
334
+ response .vary .add ("Cookie" )
335
+
332
336
# If the session is modified to be empty, remove the cookie.
333
337
# If the session is empty, return without setting the cookie.
334
338
if not session :
@@ -341,13 +345,10 @@ def save_session(
341
345
samesite = samesite ,
342
346
httponly = httponly ,
343
347
)
348
+ response .vary .add ("Cookie" )
344
349
345
350
return
346
351
347
- # Add a "Vary: Cookie" header if the session was accessed at all.
348
- if session .accessed :
349
- response .vary .add ("Cookie" )
350
-
351
352
if not self .should_set_cookie (app , session ):
352
353
return
353
354
@@ -363,3 +364,4 @@ def save_session(
363
364
secure = secure ,
364
365
samesite = samesite ,
365
366
)
367
+ response .vary .add ("Cookie" )
Original file line number Diff line number Diff line change @@ -501,6 +501,11 @@ def getitem():
501
501
def setdefault ():
502
502
return flask .session .setdefault ("test" , "default" )
503
503
504
+ @app .route ("/clear" )
505
+ def clear ():
506
+ flask .session .clear ()
507
+ return ""
508
+
504
509
@app .route ("/vary-cookie-header-set" )
505
510
def vary_cookie_header_set ():
506
511
response = flask .Response ()
@@ -533,11 +538,29 @@ def expect(path, header_value="Cookie"):
533
538
expect ("/get" )
534
539
expect ("/getitem" )
535
540
expect ("/setdefault" )
541
+ expect ("/clear" )
536
542
expect ("/vary-cookie-header-set" )
537
543
expect ("/vary-header-set" , "Accept-Encoding, Accept-Language, Cookie" )
538
544
expect ("/no-vary-header" , None )
539
545
540
546
547
+ def test_session_refresh_vary (app , client ):
548
+ @app .get ("/#" )
549
+ def login ():
550
+ flask .session ["user_id" ] = 1
551
+ flask .session .permanent = True
552
+ return ""
553
+
554
+ @app .get ("/ignored" )
555
+ def ignored ():
556
+ return ""
557
+
558
+ rv = client .get ("/#" )
559
+ assert rv .headers ["Vary" ] == "Cookie"
560
+ rv = client .get ("/ignored" )
561
+ assert rv .headers ["Vary" ] == "Cookie"
562
+
563
+
541
564
def test_flashes (app , req_ctx ):
542
565
assert not flask .session .modified
543
566
flask .flash ("Zap" )
You can’t perform that action at this time.
0 commit comments