Skip to content
Myr

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

2 files+23 added−20 removed

modified:flask/helpers.py+14 added
1002 unmodified lines
1003 else:1004 return True10051006 return False100710081009def patch_vary_header(response, value):1010 """Add a value to the ``Vary`` header if it is not already present."""10111012 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()10151016 if not any(h.lower() == lower_value for h in headers):1017 headers.append(value)10181019 updated_header = ', '.join(headers)1020 response.headers['Vary'] = updated_header
modified:flask/sessions.py+9 added-20 removed
7 unmodified lines
8 :copyright: (c) 2015 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import uuid12import hashlib13import uuid14import warnings15from base64 import b64encode, b64decode15from base64 import b64decode, b64encode16from datetime import datetime17from werkzeug.http import http_date, parse_date1718from itsdangerous import BadSignature, URLSafeTimedSerializer19from werkzeug.datastructures import CallbackDict20from werkzeug.http import http_date, parse_date2122from flask.helpers import patch_vary_header23from . import Markup, json24from ._compat import iteritems, text_type21from .helpers import total_seconds, is_ip25from .helpers import is_ip, total_seconds2623from itsdangerous import URLSafeTimedSerializer, BadSignature272528class SessionMixin(object):29 """Expands a basic dictionary with an accessors that are expected30 by Flask extensions and users for the session.31 """
374 unmodified lines
406 return407408 # 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')411412 if not self.should_set_cookie(app, session):413 return414
9 unmodified lines
424 domain=domain,425 path=path,426 secure=secure427 )426427 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]433434 if not any(h.lower() == 'cookie' for h in headers):435 headers.append('Cookie')436437 updated_header = ', '.join(headers)438 response.headers['Vary'] = updated_header