### 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.
- User's guide
- Introduction
- Asynchronous and non-Blocking I/O
- Coroutines
- Queue example - a concurrent web spider
- Structure of a Tornado web application
- Templates and UI
- Authentication and security
- Running and deploying
- Web framework
- tornado.web — RequestHandler and Application classes
- tornado.template — Flexible output generation
- tornado.escape — Escaping and string manipulation
- tornado.locale — Internationalization support
- tornado.websocket — Bidirectional communication to the browser
- HTTP servers and clients
- tornado.httpserver — Non-blocking HTTP server
- tornado.httpclient — Asynchronous HTTP client
- tornado.httputil — Manipulate HTTP headers and URLs
- tornado.http1connection – HTTP/1.x client/server implementation
- Asynchronous networking
- tornado.ioloop — Main event loop
- tornado.iostream — Convenient wrappers for non-blocking sockets
- tornado.netutil — Miscellaneous network utilities
- tornado.tcpclient — IOStream connection factory
- tornado.tcpserver — Basic IOStream-based TCP server
- Coroutines and concurrency
- tornado.gen — Simplify asynchronous code
- tornado.concurrent — Work with threads and futures
- tornado.locks – Synchronization primitives
- tornado.queues – Queues for coroutines
- tornado.process — Utilities for multiple processes
- Integration with other services
- tornado.auth — Third-party login with OpenID and OAuth
- tornado.wsgi — Interoperability with other Python frameworks and servers
- tornado.platform.asyncio — Bridge between asyncio and Tornado
- tornado.platform.caresresolver — Asynchronous DNS Resolver using C-Ares
- tornado.platform.twisted — Bridges between Twisted and Tornado
- Utilities
- tornado.autoreload — Automatically detect code changes in development
- tornado.log — Logging support
- tornado.options — Command-line parsing
- tornado.stack_context — Exception handling across asynchronous callbacks
- tornado.testing — Unit testing support for asynchronous code
- tornado.util — General-purpose utilities
- Frequently Asked Questions
- Release notes
- What's new in Tornado 4.3
- What's new in Tornado 4.2.1
- What's new in Tornado 4.2
- What's new in Tornado 4.1
- What's new in Tornado 4.0.2
- What's new in Tornado 4.0.1
- What's new in Tornado 4.0
- What's new in Tornado 3.2.2
- What's new in Tornado 3.2.1
- What's new in Tornado 3.2
- What's new in Tornado 3.1.1
- What's new in Tornado 3.1
- What's new in Tornado 3.0.2
- What's new in Tornado 3.0.1
- What's new in Tornado 3.0
- What's new in Tornado 2.4.1
- What's new in Tornado 2.4
- What's new in Tornado 2.3
- What's new in Tornado 2.2.1
- What's new in Tornado 2.2
- What's new in Tornado 2.1.1
- What's new in Tornado 2.1
- What's new in Tornado 2.0
- What's new in Tornado 1.2.1
- What's new in Tornado 1.2
- What's new in Tornado 1.1.1
- What's new in Tornado 1.1
- What's new in Tornado 1.0.1
- What's new in Tornado 1.0