:class:`~werkzeug.wrappers.Response` subclass that provides extra information about requests made with the test :class:`Client`. Test client requests will always return an instance of this class. If a custom response class is passed to the client, it is subclassed along with this to support test information. If the test request included large files, or if the application is serving a file, call :meth:`close` to close any open files and prevent Python showing a ``ResourceWarning``. .. versionchanged:: 2.2 Set the ``default_mimetype`` to None to prevent a mimetype being assumed if missing. .. versionchanged:: 2.1 Removed deprecated behavior for treating the response instance as a tuple. .. versionadded:: 2.0 Test client methods always return instances of this class.
Method | __init__ |
Undocumented |
Class Variable | __test__ |
Undocumented |
Class Variable | default |
Undocumented |
Instance Variable | history |
A list of intermediate responses. Populated when the test request is made with ``follow_redirects`` enabled. |
Instance Variable | request |
A request object with the environ used to make the request that resulted in this response. |
Property | text |
The response data as text. A shortcut for ``response.get_data(as_text=True)``. |
Instance Variable | _compat |
Undocumented |
Inherited from Response
:
Class Method | force |
Enforce that the WSGI response is a response object of the current type. Werkzeug will use the :class:`Response` internally in many situations like the exceptions. If you call :meth:`get_response` on an exception you will get back a regular :class:`Response` object, even if you are using a custom subclass. |
Class Method | from |
Create a new response object from an application output. This works best if you pass it an application that returns a generator all the time. Sometimes applications may use the `write()` callable returned by the `start_response` function... |
Method | __call__ |
Process this response as WSGI application. |
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | add |
Add an etag for the current response if there is none yet. |
Method | calculate |
Returns the content length if available or `None` otherwise. |
Method | call |
Adds a function to the internal list of functions that should be called as part of closing down the response. Since 0.7 this function also returns the function that was passed so that this can be used as a decorator. |
Method | close |
Close the wrapped response if possible. You can also use the object in a with statement which will automatically close it. |
Method | freeze |
Make the response object ready to be pickled. Does the following: |
Method | get |
Returns the application iterator for the given environ. Depending on the request method and the current status code the return value might be an empty response rather than the one from the response. |
Method | get |
The string representation of the response body. Whenever you call this property the response iterable is encoded and flattened. This can lead to unwanted behavior if you stream big data. |
Method | get |
Parse :attr:`data` as JSON. Useful during testing. |
Method | get |
This is automatically called right before the response is started and returns headers modified for the given environment. It returns a copy of the headers from the response with some modifications applied if necessary. |
Method | get |
Returns the final WSGI response as tuple. The first item in the tuple is the application iterator, the second the status and the third the list of headers. The response returned is created specially for the given environment... |
Method | iter |
Iter the response encoded with the encoding of the response. If the response object is invoked as WSGI application the return value of this method is used as application iterator unless :attr:`direct_passthrough` was activated. |
Method | make |
Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set. |
Method | make |
Converts the response iterator in a list. By default this happens automatically if required. If `implicit_sequence_conversion` is disabled, this method is not automatically called and some properties might raise exceptions... |
Method | set |
Sets a new string as response. The value must be a string or bytes. If a string is set it's encoded to the charset of the response (utf-8 by default). |
Class Variable | autocorrect |
Undocumented |
Class Variable | automatically |
Undocumented |
Class Variable | data |
Undocumented |
Class Variable | implicit |
Undocumented |
Instance Variable | content |
The ``Content-Range`` header as a :class:`~werkzeug.datastructures.ContentRange` object. Available even if the header is not set. |
Instance Variable | direct |
Undocumented |
Instance Variable | response |
Undocumented |
Instance Variable | status |
The HTTP status code as a number. |
Property | is |
If the iterator is buffered, this property will be `True`. A response object will consider an iterator to be buffered if the response attribute is a list or tuple. |
Property | is |
If the response is streamed (the response is not an iterable with a length information) this property is `True`. In this case streamed means that there is no information about the number of iterations... |
Property | json |
The parsed JSON data if :attr:`mimetype` indicates JSON (:mimetype:`application/json`, see :attr:`is_json`). |
Property | stream |
The response iterable as write-only stream. |
Method | _ensure |
This method can be called by methods that need a sequence. If `mutable` is true, it will also ensure that the response sequence is a standard Python list. |
Method | _is |
Return ``True`` if `Range` header is present and if underlying resource is considered unchanged when compared with `If-Range` header. |
Method | _process |
Handle Range Request related headers (RFC7233). If `Accept-Ranges` header is valid, and Range Request is processable, we set the headers as described by the RFC, and wrap the underlying response in a RangeWrapper. |
Method | _wrap |
Wrap existing Response in case of Range Request context. |
Instance Variable | _on |
Undocumented |
Inherited from Response
(via Response
):
Method | access |
Undocumented |
Method | content |
Undocumented |
Method | content |
Undocumented |
Method | content |
Undocumented |
Method | delete |
Delete a cookie. Fails silently if key doesn't exist. |
Method | get |
Return a tuple in the form ``(etag, is_weak)``. If there is no ETag the return value is ``(None, None)``. |
Method | mimetype |
Undocumented |
Method | retry |
Undocumented |
Method | set |
Sets a cookie. |
Method | set |
Set the etag, and override the old one if there was one. |
Method | status |
Undocumented |
Method | status |
Undocumented |
Class Variable | accept |
Undocumented |
Class Variable | access |
Undocumented |
Class Variable | access |
Undocumented |
Class Variable | access |
Undocumented |
Class Variable | access |
Undocumented |
Class Variable | access |
Undocumented |
Class Variable | age |
Undocumented |
Class Variable | allow |
Undocumented |
Class Variable | charset |
Undocumented |
Class Variable | content |
Undocumented |
Class Variable | content |
Undocumented |
Class Variable | content |
Undocumented |
Class Variable | content |
Undocumented |
Class Variable | content |
Undocumented |
Class Variable | content |
Undocumented |
Class Variable | cross |
Undocumented |
Class Variable | cross |
Undocumented |
Class Variable | date |
Undocumented |
Class Variable | default |
Undocumented |
Class Variable | expires |
Undocumented |
Class Variable | last |
Undocumented |
Class Variable | location |
Undocumented |
Class Variable | max |
Undocumented |
Class Variable | vary |
Undocumented |
Instance Variable | headers |
Undocumented |
Property | access |
Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request. |
Property | cache |
The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain. |
Property | content |
The ``Content-Security-Policy`` header as a :class:`~werkzeug.datastructures.ContentSecurityPolicy` object. Available even if the header is not set. |
Property | content |
The ``Content-Security-policy-report-only`` header as a :class:`~werkzeug.datastructures.ContentSecurityPolicy` object. Available even if the header is not set. |
Property | is |
Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`. |
Property | mimetype |
The mimetype (content type without charset etc.) |
Property | mimetype |
The mimetype parameters as dict. For example if the content type is ``text/html; charset=utf-8`` the params would be ``{'charset': 'utf-8'}``. |
Property | retry |
The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client. |
Property | status |
The HTTP status code as a string. |
Property | www |
The ``WWW-Authenticate`` header in a parsed form. |
Method | _clean |
Undocumented |
Instance Variable | _status |
Undocumented |
Instance Variable | _status |
Undocumented |
t.Iterable[ bytes]
, status: str
, headers: Headers
, request: Request
, history: t.Tuple[ TestResponse]
= (), **kwargs: t.Any
):
(source)
¶
Undocumented
A list of intermediate responses. Populated when the test request is made with ``follow_redirects`` enabled.