Skip to content
Myr

Merge pull request #2346 from davidism/2345-vary

Before adoption: this commit came in with the history the project adopted, so no landing records it.

use existing response.vary property to set vary header

authored by David Lord · committed by GitHub · parents 5797416, b8eba0a · 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

3 files+12 added−26 removed

modified:flask/helpers.py-14 removed
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+1 added-2 removed
17 unmodified lines
18from itsdangerous import BadSignature, URLSafeTimedSerializer19from werkzeug.datastructures import CallbackDict20from werkzeug.http import http_date, parse_date2122from flask.helpers import patch_vary_header22from . import Markup, json23from ._compat import iteritems, text_type24from .helpers import is_ip, total_seconds25
379 unmodified lines
405 return406407 # 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')410411 if not self.should_set_cookie(app, session):412 return413
13 unmodified lines
modified:tests/test_basic.py+11 added-10 removed
7 unmodified lines
8 :copyright: (c) 2015 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import pytest1312import pickle13import re15import uuid14import time17import flask18import pickle15import uuid16from datetime import datetime17from threading import Thread21from flask._compat import text_type22from werkzeug.exceptions import BadRequest, NotFound, Forbidden1819import pytest20import werkzeug.serving21from werkzeug.exceptions import BadRequest, Forbidden, NotFound22from werkzeug.http import parse_date23from werkzeug.routing import BuildError25import werkzeug.serving2425import flask26from flask._compat import text_type272829def test_options_work(app, client):30 @app.route('/', methods=['GET', 'POST'])31 def index():32 return 'Hello World'
490 unmodified lines
523524 @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 response530531 @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 response537538 @app.route('/no-vary-header')
1279 unmodified lines