Construct a werkzeug Response. Responses are transmitted to the browser with compression if: a) the browser supports it; b) it's sane to compress the content_type in question; and c) the content isn't already compressed, as indicated by the content_encoding parameter. Browser a
(
request,
content,
content_type,
code=200,
expires=0,
content_encoding=None,
encoding="utf-8",
csp_scripts_sha256s=None,
headers=None,
)
| 82 | |
| 83 | |
| 84 | def Respond( |
| 85 | request, |
| 86 | content, |
| 87 | content_type, |
| 88 | code=200, |
| 89 | expires=0, |
| 90 | content_encoding=None, |
| 91 | encoding="utf-8", |
| 92 | csp_scripts_sha256s=None, |
| 93 | headers=None, |
| 94 | ): |
| 95 | """Construct a werkzeug Response. |
| 96 | |
| 97 | Responses are transmitted to the browser with compression if: a) the browser |
| 98 | supports it; b) it's sane to compress the content_type in question; and c) |
| 99 | the content isn't already compressed, as indicated by the content_encoding |
| 100 | parameter. |
| 101 | |
| 102 | Browser and proxy caching is completely disabled by default. If the expires |
| 103 | parameter is greater than zero then the response will be able to be cached by |
| 104 | the browser for that many seconds; however, proxies are still forbidden from |
| 105 | caching so that developers can bypass the cache with Ctrl+Shift+R. |
| 106 | |
| 107 | For textual content that isn't JSON, the encoding parameter is used as the |
| 108 | transmission charset which is automatically appended to the Content-Type |
| 109 | header. That is unless of course the content_type parameter contains a |
| 110 | charset parameter. If the two disagree, the characters in content will be |
| 111 | transcoded to the latter. |
| 112 | |
| 113 | If content_type declares a JSON media type, then content MAY be a dict, list, |
| 114 | tuple, or set, in which case this function has an implicit composition with |
| 115 | json_util.Cleanse and json.dumps. The encoding parameter is used to decode |
| 116 | byte strings within the JSON object; therefore transmitting binary data |
| 117 | within JSON is not permitted. JSON is transmitted as ASCII unless the |
| 118 | content_type parameter explicitly defines a charset parameter, in which case |
| 119 | the serialized JSON bytes will use that instead of escape sequences. |
| 120 | |
| 121 | Args: |
| 122 | request: A werkzeug Request object. Used mostly to check the |
| 123 | Accept-Encoding header. |
| 124 | content: Payload data as byte string, unicode string, or maybe JSON. |
| 125 | content_type: Media type and optionally an output charset. |
| 126 | code: Numeric HTTP status code to use. |
| 127 | expires: Second duration for browser caching. |
| 128 | content_encoding: Encoding if content is already encoded, e.g. 'gzip'. |
| 129 | encoding: Input charset if content parameter has byte strings. |
| 130 | csp_scripts_sha256s: List of base64 serialized sha256 of whitelisted script |
| 131 | elements for script-src of the Content-Security-Policy. If it is None, the |
| 132 | HTML will disallow any script to execute. It is only be used when the |
| 133 | content_type is text/html. |
| 134 | headers: Any additional headers to include on the response, as a |
| 135 | list of key-value tuples: e.g., `[("Allow", "GET")]`. In case of |
| 136 | conflict, these may be overridden with headers added by this function. |
| 137 | |
| 138 | Returns: |
| 139 | A werkzeug Response object (a WSGI application). |
| 140 | """ |
| 141 |
no test coverage detected
searching dependent graphs…