Skip to content

Commit

Permalink
Added MAX_CONTENT_LENGTH config key
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jul 14, 2010
1 parent f8f8463 commit b1790cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Release date to be announced, codename to be decided.
as `config`. as `config`.
- context processors will no longer override values passed directly - context processors will no longer override values passed directly
to the render function. to the render function.
- added the ability to limit the incoming request data with the
new ``MAX_CONTENT_LENGTH`` configuration value.


Version 0.5.1 Version 0.5.1
------------- -------------
Expand Down
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ The following configuration values are used internally by Flask:
``LOGGER_NAME`` the name of the logger ``LOGGER_NAME`` the name of the logger
``SERVER_NAME`` the name of the server. Required for ``SERVER_NAME`` the name of the server. Required for
subdomain support (eg: ``'localhost'``) subdomain support (eg: ``'localhost'``)
``MAX_CONTENT_LENGTH`` If set to a value in bytes, Flask will
reject incoming requests with a
content length greater than this by
returning a 413 status code.
=============================== ========================================= =============================== =========================================


.. admonition:: More on ``SERVER_NAME`` .. admonition:: More on ``SERVER_NAME``
Expand Down Expand Up @@ -89,6 +93,8 @@ The following configuration values are used internally by Flask:
.. versionadded:: 0.5 .. versionadded:: 0.5
``SERVER_NAME`` ``SERVER_NAME``


.. versionadded:: ``MAX_CONTENT_LENGTH``

Configuring from Files Configuring from Files
---------------------- ----------------------


Expand Down
3 changes: 2 additions & 1 deletion flask/app.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class Flask(_PackageBoundObject):
'PERMANENT_SESSION_LIFETIME': timedelta(days=31), 'PERMANENT_SESSION_LIFETIME': timedelta(days=31),
'USE_X_SENDFILE': False, 'USE_X_SENDFILE': False,
'LOGGER_NAME': None, 'LOGGER_NAME': None,
'SERVER_NAME': None 'SERVER_NAME': None,
'MAX_CONTENT_LENGTH': None
}) })


def __init__(self, import_name, static_path=None): def __init__(self, import_name, static_path=None):
Expand Down
8 changes: 8 additions & 0 deletions flask/wrappers.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
cached_property cached_property


from .helpers import json, _assert_have_json from .helpers import json, _assert_have_json
from .globals import _request_ctx_stack




class Request(RequestBase): class Request(RequestBase):
Expand Down Expand Up @@ -41,6 +42,13 @@ class Request(RequestBase):
#: something similar. #: something similar.
routing_exception = None routing_exception = None


@property
def max_content_length(self):
"""Read-only view of the `MAX_CONTENT_LENGTH` config key."""
ctx = _request_ctx_stack.top
if ctx is not None:
return ctx.app.config['MAX_CONTENT_LENGTH']

@property @property
def endpoint(self): def endpoint(self):
"""The endpoint that matched the request. This in combination with """The endpoint that matched the request. This in combination with
Expand Down

0 comments on commit b1790cc

Please sign in to comment.