🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### Navigation - [index](# "General Index") - [modules](# "Python Module Index") | - [next](# "Asynchronous networking") | - [previous](# "tornado.httputil — Manipulate HTTP headers and URLs") | - [Tornado 4.4.dev1 documentation](#) » - [HTTP servers and clients](#) » # `tornado.http1connection` – HTTP/1.x client/server implementation 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 [`HTTP1Connection`](# "tornado.http1connection.HTTP1Connection") and [`HTTP1ServerConnection`](# "tornado.http1connection.HTTP1ServerConnection"). <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"><li><strong>no_keep_alive</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#bool" title="(in Python v3.4)"><em>bool</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#bool]</span>) – If true, always close the connection afterone request.</li><li><strong>chunk_size</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#int" title="(in Python v3.4)"><em>int</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#int]</span>) – how much data to read into memory at once</li><li><strong>max_header_size</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#int" title="(in Python v3.4)"><em>int</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#int]</span>) – maximum amount of data for HTTP headers</li><li><strong>header_timeout</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#float" title="(in Python v3.4)"><em>float</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#float]</span>) – how long to wait for all headers (seconds)</li><li><strong>max_body_size</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#int" title="(in Python v3.4)"><em>int</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#int]</span>) – maximum amount of data for body</li><li><strong>body_timeout</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#float" title="(in Python v3.4)"><em>float</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#float]</span>) – how long to wait while reading body (seconds)</li><li><strong>decompress</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#bool" title="(in Python v3.4)"><em>bool</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#bool]</span>) – if true, decode incoming<code class="docutils literal"><span class="pre">Content-Encoding:</span> <span class="pre">gzip</span></code></li></ul></td></tr></tbody></table> *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 [`HTTP1ServerConnection`](# "tornado.http1connection.HTTP1ServerConnection")for servers. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"><li><strong>stream</strong> – an <a class="reference internal" href="iostream.html#tornado.iostream.IOStream" title="tornado.iostream.IOStream"><code class="xref py py-obj docutils literal"><span class="pre">IOStream</span></code></a></li><li><strong>is_client</strong> (<a class="reference external" href="https://docs.python.org/3.4/library/functions.html#bool" title="(in Python v3.4)"><em>bool</em></a><span class="link-target"> [https://docs.python.org/3.4/library/functions.html#bool]</span>) – client or server</li><li><strong>params</strong> – a <a class="reference internal" href="#tornado.http1connection.HTTP1ConnectionParameters" title="tornado.http1connection.HTTP1ConnectionParameters"><code class="xref py py-obj docutils literal"><span class="pre">HTTP1ConnectionParameters</span></code></a> instance or <code class="docutils literal"><span class="pre">None</span></code></li><li><strong>context</strong> – an opaque application-defined object that can be accessedas <code class="docutils literal"><span class="pre">connection.context</span></code>.</li></ul></td></tr></tbody></table> `read_response`(*delegate*)[[source]](#) Read a single HTTP response. Typical client-mode usage is to write a request using [`write_headers`](# "tornado.http1connection.HTTP1Connection.write_headers"),[`write`](# "tornado.http1connection.HTTP1Connection.write"), and [`finish`](# "tornado.http1connection.HTTP1Connection.finish"), and then call `read_response`. | Parameters: | **delegate** – a [`HTTPMessageDelegate`](# "tornado.httputil.HTTPMessageDelegate") | |-----|-----| Returns a [`Future`](# "tornado.concurrent.Future") that resolves to None after the full response hasbeen 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_close`](# "tornado.httputil.HTTPMessageDelegate.on_connection_close") instead. `detach`()[[source]](#) Take control of the underlying stream. Returns the underlying [`IOStream`](# "tornado.iostream.IOStream") object and stops all furtherHTTP processing. May only be called during[`HTTPMessageDelegate.headers_received`](# "tornado.httputil.HTTPMessageDelegate.headers_received"). Intended for implementingprotocols 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`](# "tornado.http1connection.HTTP1ConnectionParameters"). `set_max_body_size`(*max_body_size*)[[source]](#) Sets the body size limit for a single request. Overrides the value from [`HTTP1ConnectionParameters`](# "tornado.http1connection.HTTP1ConnectionParameters"). `write_headers`(*start_line*, *headers*, *chunk=None*, *callback=None*)[[source]](#) Implements [`HTTPConnection.write_headers`](# "tornado.httputil.HTTPConnection.write_headers"). `write`(*chunk*, *callback=None*)[[source]](#) Implements [`HTTPConnection.write`](# "tornado.httputil.HTTPConnection.write"). For backwards compatibility is is allowed but deprecated toskip [`write_headers`](# "tornado.http1connection.HTTP1Connection.write_headers") and instead call [`write()`](# "tornado.http1connection.HTTP1Connection.write") with apre-encoded header block. `finish`()[[source]](#) Implements [`HTTPConnection.finish`](# "tornado.httputil.HTTPConnection.finish"). *class *`tornado.http1connection.``HTTP1ServerConnection`(*stream*, *params=None*, *context=None*)[[source]](#) An HTTP/1.x server. <table class="docutils field-list" frame="void" rules="none"><col class="field-name"/><col class="field-body"/><tbody valign="top"><tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"><li><strong>stream</strong> – an <a class="reference internal" href="iostream.html#tornado.iostream.IOStream" title="tornado.iostream.IOStream"><code class="xref py py-obj docutils literal"><span class="pre">IOStream</span></code></a></li><li><strong>params</strong> – a <a class="reference internal" href="#tornado.http1connection.HTTP1ConnectionParameters" title="tornado.http1connection.HTTP1ConnectionParameters"><code class="xref py py-obj docutils literal"><span class="pre">HTTP1ConnectionParameters</span></code></a> or None</li><li><strong>context</strong> – an opaque application-defined object that is accessibleas <code class="docutils literal"><span class="pre">connection.context</span></code></li></ul></td></tr></tbody></table> `close`()[[source]](#) Closes the connection. Returns a [`Future`](# "tornado.concurrent.Future") that resolves after the serving loop has exited. `start_serving`(*delegate*)[[source]](#) Starts serving requests on this connection. | Parameters: | **delegate** – a [`HTTPServerConnectionDelegate`](# "tornado.httputil.HTTPServerConnectionDelegate") | |-----|-----| © Copyright 2009-2016, The Tornado Authors. Created using [Sphinx](http://sphinx-doc.org/) 1.3.5.