Skip to content
Myr

add Response.max_cookie_size config

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 465b48e · Browse files · 6 files+65 added−5 removed
This commit

State

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

Diff stats

6 files+65 added−5 removed

  • tests:+30 added−0 removed
  • other:+35 added−5 removed

6 files+65 added−5 removed

modified:docs/api.rst+1 added-1 removed
83 unmodified lines
84Response Objects85----------------8687.. autoclass:: flask.Response88 :members: set_cookie, data, mimetype, is_json, get_json88 :members: set_cookie, max_cookie_size, data, mimetype, is_json, get_json8990 .. attribute:: headers9192 A :class:`~werkzeug.datastructures.Headers` object representing the response headers.
730 unmodified lines
modified:docs/config.rst+8 added
341 unmodified lines
342 appears to be loaded.343344 Default: ``False``345346.. py:data:: MAX_COOKIE_SIZE347348 Warn if cookie headers are larger than this many bytes. Defaults to349 ``4093``. Larger cookies may be silently ignored by browsers. Set to350 ``0`` to disable the warning.351352.. versionadded:: 0.4353 ``LOGGER_NAME``354355.. versionadded:: 0.5
30 unmodified lines
386387 Added :data:`SESSION_COOKIE_SAMESITE` to control the session388 cookie's ``SameSite`` option.389390 Added :data:`MAX_COOKIE_SIZE` to control a warning from Werkzeug.391392393Configuring from Files394----------------------395396Configuration becomes more useful if you can store it in a separate file,
262 unmodified lines
modified:flask/app.py+1 added
303 unmodified lines
304 'JSON_SORT_KEYS': True,305 'JSONIFY_PRETTYPRINT_REGULAR': False,306 'JSONIFY_MIMETYPE': 'application/json',307 'TEMPLATES_AUTO_RELOAD': None,308 'MAX_COOKIE_SIZE': 4093,309 })310311 #: The rule object to use for URL rules created. This is used by312 #: :meth:`add_url_rule`. Defaults to :class:`werkzeug.routing.Rule`.
1995 unmodified lines
modified:flask/wrappers.py+17 added
189 unmodified lines
190191 .. versionchanged:: 1.0192 JSON support is added to the response, like the request. This is useful193 when testing to get the test client response data as JSON.194195 .. versionchanged:: 1.0196197 Added :attr:`max_cookie_size`.198 """199200 default_mimetype = 'text/html'201202 def _get_data_for_json(self, cache):203 return self.get_data()204205 @property206 def max_cookie_size(self):207 """Read-only view of the :data:`MAX_COOKIE_SIZE` config key.208209 See :attr:`~werkzeug.wrappers.BaseResponse.max_cookie_size` in210 Werkzeug's docs.211 """212 if current_app:213 return current_app.config['MAX_COOKIE_SIZE']214215 # return Werkzeug's default when not in an app context216 return super(Response, self).max_cookie_size
modified:tests/test_basic.py+30 added
1915 unmodified lines
19161917 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1918 app.config['SERVER_NAME'] = 'pocoo.org:8080'1919 app.run(host, port)192019211922def test_max_cookie_size(app, client, recwarn):1923 app.config['MAX_COOKIE_SIZE'] = 10019241925 # outside app context, default to Werkzeug static value,1926 # which is also the default config1927 response = flask.Response()1928 default = flask.Flask.default_config['MAX_COOKIE_SIZE']1929 assert response.max_cookie_size == default19301931 # inside app context, use app config1932 with app.app_context():1933 assert flask.Response().max_cookie_size == 10019341935 @app.route('/')1936 def index():1937 r = flask.Response('', status=204)1938 r.set_cookie('foo', 'bar' * 100)1939 return r19401941 client.get('/')1942 assert len(recwarn) == 11943 w = recwarn.pop()1944 assert 'cookie is too large' in str(w.message)19451946 app.config['MAX_COOKIE_SIZE'] = 019471948 client.get('/')1949 assert len(recwarn) == 0
modified:CHANGES.rst+8 added-4 removed
143 unmodified lines
144 passing ``subdomain_matching=True`` to the ``Flask`` constructor.145 (`#2635`_)146- A single trailing slash is stripped from the blueprint ``url_prefix``147 when it is registered with the app. (`#2629`_)148- :meth:`Request.get_json() <flask.Request.get_json>` doesn't cache the148- :meth:`Request.get_json` doesn't cache the149 result if parsing fails when ``silent`` is true. (`#2651`_)150- :func:`request.get_json <flask.Request.get_json>` no longer accepts151 arbitrary encodings. Incoming JSON should be encoded using UTF-8 per152 :rfc:`8259`, but Flask will autodetect UTF-8, -16, or -32. (`#2691`_)150- :func:`Request.get_json` no longer accepts arbitrary encodings.151 Incoming JSON should be encoded using UTF-8 per :rfc:`8259`, but Flask152 will autodetect UTF-8, -16, or -32. (`#2691`_)153- Added :data:`MAX_COOKIE_SIZE` and :attr:`Response.max_cookie_size` to154 control when Werkzeug warns about large cookies that browsers may155 ignore. (`#2693`_)156157.. _pallets/meta#24: https://github.com/pallets/meta/issues/24158.. _#1421: https://github.com/pallets/flask/issues/1421159.. _#1489: https://github.com/pallets/flask/pull/1489
38 unmodified lines
198.. _#2635: https://github.com/pallets/flask/pull/2635199.. _#2629: https://github.com/pallets/flask/pull/2629200.. _#2651: https://github.com/pallets/flask/issues/2651201.. _#2691: https://github.com/pallets/flask/pull/2691202.. _#2693: https://github.com/pallets/flask/pull/2693203204205Version 0.12.2206--------------
618 unmodified lines