tornado.http1connection – HTTP/1.x client/server 实现¶
Client and server implementations of HTTP/1.x.
New in version 4.0.
-
class
tornado.http1connection.HTTP1ConnectionParameters(no_keep_alive=False, chunk_size=None, max_header_size=None, header_timeout=None, max_body_size=None, body_timeout=None, decompress=False)[source]¶ Parameters for
HTTP1ConnectionandHTTP1ServerConnection.Parameters: - 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
Content-Encoding: gzip
-
class
tornado.http1connection.HTTP1Connection(stream, is_client, params=None, context=None)[source]¶ Implements the HTTP/1.x protocol.
This class can be on its own for clients, or via
HTTP1ServerConnectionfor servers.Parameters: - stream – an
IOStream - is_client (bool) – client or server
- params – a
HTTP1ConnectionParametersinstance orNone - context – an opaque application-defined object that can be accessed
as
connection.context.
-
read_response(delegate)[source]¶ Read a single HTTP response.
Typical client-mode usage is to write a request using
write_headers,write, andfinish, and then callread_response.Parameters: delegate – a HTTPMessageDelegateReturns a
Futurethat resolves to None after the full response has been read.
-
set_close_callback(callback)[source]¶ Sets a callback that will be run when the connection is closed.
Deprecated since version 4.0: Use
HTTPMessageDelegate.on_connection_closeinstead.
-
detach()[source]¶ Take control of the underlying stream.
Returns the underlying
IOStreamobject and stops all further HTTP processing. May only be called duringHTTPMessageDelegate.headers_received. Intended for implementing protocols like websockets that tunnel over an HTTP handshake.
-
set_body_timeout(timeout)[source]¶ Sets the body timeout for a single request.
Overrides the value from
HTTP1ConnectionParameters.
-
set_max_body_size(max_body_size)[source]¶ Sets the body size limit for a single request.
Overrides the value from
HTTP1ConnectionParameters.
-
write_headers(start_line, headers, chunk=None, callback=None)[source]¶ Implements
HTTPConnection.write_headers.
-
write(chunk, callback=None)[source]¶ Implements
HTTPConnection.write.For backwards compatibility is is allowed but deprecated to skip
write_headersand instead callwrite()with a pre-encoded header block.
-
finish()[source]¶ Implements
HTTPConnection.finish.
- stream – an
-
class
tornado.http1connection.HTTP1ServerConnection(stream, params=None, context=None)[source]¶ An HTTP/1.x server.
Parameters: - stream – an
IOStream - params – a
HTTP1ConnectionParametersor None - context – an opaque application-defined object that is accessible
as
connection.context
-
close(*args, **kwargs)[source]¶ Closes the connection.
Returns a
Futurethat resolves after the serving loop has exited.
-
start_serving(delegate)[source]¶ Starts serving requests on this connection.
Parameters: delegate – a HTTPServerConnectionDelegate
- stream – an