tornado.http1connection – HTTP/1.x client/server implementation¶
Client and server implementations of HTTP/1.x.
New in version 4.0.
HTTP1ConnectionParameters(no_keep_alive: bool = False, chunk_size: int = None, max_header_size: int = None, header_timeout: float = None, max_body_size: int = None, body_timeout: float = None, decompress: bool = False)¶
- no_keep_alive (bool) – If true, always close the connection after one request.
- chunk_size (int) – how much data to read into memory at once
- max_header_size (int) – maximum amount of data for HTTP headers
- header_timeout (float) – how long to wait for all headers (seconds)
- max_body_size (int) – maximum amount of data for body
- body_timeout (float) – how long to wait while reading body (seconds)
- decompress (bool) – if true, decode incoming
HTTP1Connection(stream: tornado.iostream.IOStream, is_client: bool, params: tornado.http1connection.HTTP1ConnectionParameters = None, context: object = None)¶
Implements the HTTP/1.x protocol.
This class can be on its own for clients, or via
read_response(delegate: tornado.httputil.HTTPMessageDelegate) → Awaitable[bool]¶
Read a single HTTP response.
Parameters: delegate – a
Futurethat resolves to a bool after the full response has been read. The result is true if the stream is still open.
set_close_callback(callback: Optional[Callable[, None]]) → None¶
Sets a callback that will be run when the connection is closed.
Note that this callback is slightly different from
HTTPMessageDelegatemethod is called when the connection is closed while recieving a message. This callback is used when there is not an active delegate (for example, on the server side this callback is used if the client closes the connection after sending its request but before receiving all the response.
detach() → tornado.iostream.IOStream¶
Take control of the underlying stream.
Returns the underlying
IOStreamobject and stops all further HTTP processing. May only be called during
HTTPMessageDelegate.headers_received. Intended for implementing protocols like websockets that tunnel over an HTTP handshake.
set_body_timeout(timeout: float) → None¶
Sets the body timeout for a single request.
Overrides the value from
set_max_body_size(max_body_size: int) → None¶
Sets the body size limit for a single request.
Overrides the value from
write_headers(start_line: Union[tornado.httputil.RequestStartLine, tornado.httputil.ResponseStartLine], headers: tornado.httputil.HTTPHeaders, chunk: bytes = None) → Future[None]¶
write(chunk: bytes) → Future[None]¶
HTTP1ServerConnection(stream: tornado.iostream.IOStream, params: tornado.http1connection.HTTP1ConnectionParameters = None, context: object = None)¶
An HTTP/1.x server.
close() → None¶
Closes the connection.
Futurethat resolves after the serving loop has exited.