extract patch_vary_header to helpers
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent e7cd68b · Browse files · 2 files·+23 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+23 added−20 removed
- other:+23 added−20 removed
Provenance
- Commit
bdf31cd- Tree
c48fc54- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
e7cd68b
2 files changed+23 added−20 removed
modified:flask/helpers.py+14 added
1002 unmodified lines1003 else:1004 return True1005 1006 return False1007+1008+1009+def patch_vary_header(response, value):1010+ """Add a value to the ``Vary`` header if it is not already present."""1011+1012+ header = response.headers.get('Vary', '')1013+ headers = [h for h in (h.strip() for h in header.split(',')) if h]1014+ lower_value = value.lower()1015+1016+ if not any(h.lower() == lower_value for h in headers):1017+ headers.append(value)1018+1019+ updated_header = ', '.join(headers)1020+ response.headers['Vary'] = updated_headermodified:flask/sessions.py+9 added-20 removed
7 unmodified lines8 :copyright: (c) 2015 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-import uuid12 import hashlib13+import uuid14 import warnings15-from base64 import b64encode, b64decode15+from base64 import b64decode, b64encode16 from datetime import datetime17-from werkzeug.http import http_date, parse_date17+18+from itsdangerous import BadSignature, URLSafeTimedSerializer19 from werkzeug.datastructures import CallbackDict20+from werkzeug.http import http_date, parse_date21+22+from flask.helpers import patch_vary_header23 from . import Markup, json24 from ._compat import iteritems, text_type21-from .helpers import total_seconds, is_ip25+from .helpers import is_ip, total_seconds26 23-from itsdangerous import URLSafeTimedSerializer, BadSignature27 25-28 class SessionMixin(object):29 """Expands a basic dictionary with an accessors that are expected30 by Flask extensions and users for the session.31 """374 unmodified lines406 return407 408 # Add a "Vary: Cookie" header if the session was accessed at all.409 if session.accessed:408- self._patch_vary_cookie_header(response)410+ patch_vary_header(response, 'Cookie')411 412 if not self.should_set_cookie(app, session):413 return414 9 unmodified lines424 domain=domain,425 path=path,426 secure=secure427 )426-427- def _patch_vary_cookie_header(self, response):428- """429- Add a 'Cookie' value to the 'Vary' header if one is not already present.430- """431- header = response.headers.get('Vary', '')432- headers = [h.strip() for h in header.split(',') if h]433-434- if not any(h.lower() == 'cookie' for h in headers):435- headers.append('Cookie')436-437- updated_header = ', '.join(headers)438- response.headers['Vary'] = updated_header