Convert some object into a Response. Supported objects are:
<meta>
tag specifying the encoding);(code, *headers, something_else)
tuples where something_else
is
one of the other supported objects and headers
is an arbitrary amount
of (name, value)
tuples;This function is a coroutine.
Encode a JSON object with json.dumps
, return a Response
with an appropriate Content-Type
set.
An exception that signals HTTP errors. description
must be a string;
headers
has to be something that can be converted into a dict.
Now as a struct.Headers.
What this error code means according to the HTTP standard.
A single-chunk response. data
must be a bytes
object, headers
should be
convertable into a dict.
A list of chunks.
Now as a struct.Headers.
A property that returns some headers. These will be sent to the client unless overriden in the constructor. By default, these are:
Content-Type: text/html; charset=utf-8
Content-Length
: whatever the length of data
is.Called after the response is sent to the client. reader
is an
asyncio.StreamReader the request was received from,
writer
is an asyncio.StreamWriter the response was
sent through. Useful for upgrading to other protocols (e.g. HTTP 2 or WebSocket.)
This method is a coroutine.
A response that sends data from a local file instead of a string. Inherits Response. If the file does not exist or is not readable, constructor throws HTTP 404.
Same as Response.defheaders, except Content-Length
is determined
via os.stat.
A property that returns an iterator of chunks, then closes the file after yielding the last one.
Raise Abort. Accepts the same arguments.
Issue a redirect to another path by raising Abort
with a Location
header.
By default, code
is 302 (Found).
Guess the MIME type from the file name, create a FileResponse.
If attachment
is true, Content-Disposition
is set to attachment
(meaning browsers will download the file instead of attempting to display it.)
NOTE: this function will happily send any file; normalize the filename first
if you’ve received it from an unknown source! For example, a client can easily
request /static/../../../../../../../etc/passwd
; to avoid this,
call os.path.normpath
before os.path.join.