use existing response.vary property to set vary header
Before adoption: this commit came in with the history the project adopted, so no landing records it.
closes #2345
authored by David Lord · committed by David Lord · parent 5797416 · Browse files · 3 files·+12 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+12 added−26 removed
- tests:+11 added−10 removed
- other:+1 added−16 removed
Provenance
- Commit
b8eba0a- Tree
34bbb87- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
5797416
3 files changed+12 added−26 removed
modified:flask/helpers.py-14 removed
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+1 added-2 removed
17 unmodified lines18 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_header22 from . import Markup, json23 from ._compat import iteritems, text_type24 from .helpers import is_ip, total_seconds25 379 unmodified lines405 return406 407 # Add a "Vary: Cookie" header if the session was accessed at all.408 if session.accessed:410- patch_vary_header(response, 'Cookie')409+ response.vary.add('Cookie')410 411 if not self.should_set_cookie(app, session):412 return413 13 unmodified linesmodified:tests/test_basic.py+11 added-10 removed
7 unmodified lines8 :copyright: (c) 2015 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-import pytest13-12+import pickle13 import re15-import uuid14 import time17-import flask18-import pickle15+import uuid16 from datetime import datetime17 from threading import Thread21-from flask._compat import text_type22-from werkzeug.exceptions import BadRequest, NotFound, Forbidden18+19+import pytest20+import werkzeug.serving21+from werkzeug.exceptions import BadRequest, Forbidden, NotFound22 from werkzeug.http import parse_date23 from werkzeug.routing import BuildError25-import werkzeug.serving24 25+import flask26+from flask._compat import text_type27 28+29 def test_options_work(app, client):30 @app.route('/', methods=['GET', 'POST'])31 def index():32 return 'Hello World'490 unmodified lines523 524 @app.route('/vary-cookie-header-set')525 def vary_cookie_header_set():526 response = flask.Response()526- response.headers['Vary'] = 'Cookie'527+ response.vary.add('Cookie')528 flask.session['test'] = 'test'529 return response530 531 @app.route('/vary-header-set')532 def vary_header_set():533 response = flask.Response()533- response.headers['Vary'] = 'Accept-Encoding, Accept-Language'534+ response.vary.update(('Accept-Encoding', 'Accept-Language'))535 flask.session['test'] = 'test'536 return response537 538 @app.route('/no-vary-header')1279 unmodified lines