diff --git a/docs/api.rst b/docs/api.rst index e5f68b8d..8ca1e42c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -27,9 +27,9 @@ Incoming Request Data --------------------- .. autoclass:: Request - :members: - :inherited-members: - :exclude-members: json_module + :members: + :inherited-members: + :exclude-members: json_module .. attribute:: request @@ -48,20 +48,9 @@ Response Objects ---------------- .. autoclass:: flask.Response - :members: set_cookie, max_cookie_size, data, mimetype, is_json, get_json - - .. attribute:: headers - - A :class:`~werkzeug.datastructures.Headers` object representing the response headers. - - .. attribute:: status - - A string with a response status. - - .. attribute:: status_code - - The response status as integer. - + :members: + :inherited-members: + :exclude-members: json_module Sessions -------- diff --git a/src/flask/wrappers.py b/src/flask/wrappers.py index 76a12bd0..279561a6 100644 --- a/src/flask/wrappers.py +++ b/src/flask/wrappers.py @@ -1,23 +1,12 @@ from werkzeug.exceptions import BadRequest from werkzeug.wrappers import Request as RequestBase from werkzeug.wrappers import Response as ResponseBase -from werkzeug.wrappers.json import JSONMixin as _JSONMixin from . import json from .globals import current_app -class JSONMixin(_JSONMixin): - json_module = json - - def on_json_loading_failed(self, e): - if current_app and current_app.debug: - raise BadRequest(f"Failed to decode JSON object: {e}") - - raise BadRequest() - - -class Request(RequestBase, JSONMixin): +class Request(RequestBase): """The request object used by default in Flask. Remembers the matched endpoint and view arguments. @@ -30,6 +19,8 @@ class Request(RequestBase, JSONMixin): specific ones. """ + json_module = json + #: The internal URL rule that matched the request. This can be #: useful to inspect which methods are allowed for the URL from #: a before/after handler (``request.url_rule.methods``) etc. @@ -89,8 +80,14 @@ class Request(RequestBase, JSONMixin): attach_enctype_error_multidict(self) + def on_json_loading_failed(self, e): + if current_app and current_app.debug: + raise BadRequest(f"Failed to decode JSON object: {e}") -class Response(JSONMixin, ResponseBase): + raise BadRequest() + + +class Response(ResponseBase): """The response object that is used by default in Flask. Works like the response object from Werkzeug but is set to have an HTML mimetype by default. Quite often you don't have to create this object yourself because @@ -110,8 +107,7 @@ class Response(JSONMixin, ResponseBase): default_mimetype = "text/html" - def _get_data_for_json(self, cache): - return self.get_data() + json_module = json @property def max_cookie_size(self):