tornado.http1connection – HTTP/1.x client/server implementation¶
Client and server implementations of HTTP/1.x.
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)[源代码]¶
Parameters forHTTP1Connection
andHTTP1ServerConnection
.
|参数:
|——-
|
- no_keep_alive (bool) – If true, always close the connection afterone 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 incomingContent-Encoding: gzip
- class
tornado.http1connection.
HTTP1Connection
(stream, is_client, params=None, context=None)[源代码]¶
Implements the HTTP/1.x protocol.
This class can be on its own for clients, or viaHTTP1ServerConnection
for servers.
|参数:
|——-
|
- stream – an IOStream
- is_client (bool) – client or server
- params – a HTTP1ConnectionParameters instance or None
- context – an opaque application-defined object that can be accessedas connection.context.readresponse
(_delegate)[源代码]¶
Read a single HTTP response.
Typical client-mode usage is to write a request usingwrite_headers
,write
, andfinish
, and then callreadresponse
.
|参数:
|——-
|delegate – aHTTPMessageDelegate
Returns aFuture
that resolves to None after the full response hasbeen read.
set_close_callback
(_callback)[源代码]¶
Sets a callback that will be run when the connection is closed.
4.0 版后已移除: UseHTTPMessageDelegate.on_connection_close
instead.
detach
()[源代码]¶
Take control of the underlying stream.
Returns the underlyingIOStream
object and stops all furtherHTTP processing. May only be called duringHTTPMessageDelegate.headers_received
. Intended for implementingprotocols like websockets that tunnel over an HTTP handshake.
setbody_timeout
(_timeout)[源代码]¶
Sets the body timeout for a single request.
Overrides the value fromHTTP1ConnectionParameters
.
setmax_body_size
(_max_body_size)[源代码]¶
Sets the body size limit for a single request.
Overrides the value fromHTTP1ConnectionParameters
.
writeheaders
(_start_line, headers, chunk=None, callback=None)[源代码]¶
ImplementsHTTPConnection.write_headers
.
write
(chunk, callback=None)[源代码]¶
ImplementsHTTPConnection.write
.
For backwards compatibility is is allowed but deprecated toskipwrite_headers
and instead callwrite()
with apre-encoded header block.
finish
()[源代码]¶
ImplementsHTTPConnection.finish
.
- class
tornado.http1connection.
HTTP1ServerConnection
(stream, params=None, context=None)[源代码]¶
An HTTP/1.x server.
|参数:
|——-
|
- stream – an IOStream
- params – a HTTP1ConnectionParameters or None
- context – an opaque application-defined object that is accessibleas connection.contextclose
(*args, **kwargs)[源代码]¶
Closes the connection.
Returns aFuture
that resolves after the serving loop has exited.
startserving
(_delegate)[源代码]¶
Starts serving requests on this connection.
|参数:
|——-
|delegate – aHTTPServerConnectionDelegate
原文:
https://tornado-zh-cn.readthedocs.io/zh_CN/latest/http1connection.html