|
|
@ -9,18 +9,20 @@ |
|
|
|
:license: BSD, see LICENSE for more details. |
|
|
|
:license: BSD, see LICENSE for more details. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
import uuid |
|
|
|
|
|
|
|
import hashlib |
|
|
|
import hashlib |
|
|
|
|
|
|
|
import uuid |
|
|
|
import warnings |
|
|
|
import warnings |
|
|
|
from base64 import b64encode, b64decode |
|
|
|
from base64 import b64decode, b64encode |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
from werkzeug.http import http_date, parse_date |
|
|
|
|
|
|
|
|
|
|
|
from itsdangerous import BadSignature, URLSafeTimedSerializer |
|
|
|
from werkzeug.datastructures import CallbackDict |
|
|
|
from werkzeug.datastructures import CallbackDict |
|
|
|
|
|
|
|
from werkzeug.http import http_date, parse_date |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from flask.helpers import patch_vary_header |
|
|
|
from . import Markup, json |
|
|
|
from . import Markup, json |
|
|
|
from ._compat import iteritems, text_type |
|
|
|
from ._compat import iteritems, text_type |
|
|
|
from .helpers import total_seconds, is_ip |
|
|
|
from .helpers import is_ip, total_seconds |
|
|
|
|
|
|
|
|
|
|
|
from itsdangerous import URLSafeTimedSerializer, BadSignature |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SessionMixin(object): |
|
|
|
class SessionMixin(object): |
|
|
@ -405,7 +407,7 @@ class SecureCookieSessionInterface(SessionInterface): |
|
|
|
|
|
|
|
|
|
|
|
# Add a "Vary: Cookie" header if the session was accessed at all. |
|
|
|
# Add a "Vary: Cookie" header if the session was accessed at all. |
|
|
|
if session.accessed: |
|
|
|
if session.accessed: |
|
|
|
self._patch_vary_cookie_header(response) |
|
|
|
patch_vary_header(response, 'Cookie') |
|
|
|
|
|
|
|
|
|
|
|
if not self.should_set_cookie(app, session): |
|
|
|
if not self.should_set_cookie(app, session): |
|
|
|
return |
|
|
|
return |
|
|
@ -423,16 +425,3 @@ class SecureCookieSessionInterface(SessionInterface): |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
secure=secure |
|
|
|
secure=secure |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def _patch_vary_cookie_header(self, response): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Add a 'Cookie' value to the 'Vary' header if one is not already present. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
header = response.headers.get('Vary', '') |
|
|
|
|
|
|
|
headers = [h.strip() for h in header.split(',') if h] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not any(h.lower() == 'cookie' for h in headers): |
|
|
|
|
|
|
|
headers.append('Cookie') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updated_header = ', '.join(headers) |
|
|
|
|
|
|
|
response.headers['Vary'] = updated_header |
|
|
|
|
|
|
|