.. automodule:: tornado.httpserver
- ``HTTPRequest`` objects
- -----------------------
- .. autoclass:: HTTPRequest
- :members:
-
HTTP Server
-----------
.. autoclass:: HTTPServer
:members:
-
- .. autoclass:: HTTPConnection
- :members:
- ``path`` - the request path (everything before the ``?``)
- ``headers`` - the request headers
-See the class definition for `tornado.httpserver.HTTPRequest` for a
+See the class definition for `tornado.httputil.HTTPServerRequest` for a
complete list of attributes.
Overriding RequestHandler methods
* To facilitate some advanced multi-process scenarios, ``HTTPServer``
has a new method ``add_sockets``, and socket-opening code is
available separately as `tornado.netutil.bind_sockets`.
-* The ``cookies`` property is now available on `tornado.httpserver.HTTPRequest`
+* The ``cookies`` property is now available on ``tornado.httpserver.HTTPRequest``
(it is also available in its old location as a property of
`~tornado.web.RequestHandler`)
* ``tornado.httpserver.HTTPServer.bind`` now takes a backlog argument with the
* `.HTTPServer` now works correctly with paths starting with ``//``
* ``HTTPHeaders.copy`` (inherited from `dict.copy`) now works correctly.
* ``HTTPConnection.address`` is now always the socket address, even for non-IP
- sockets. `.HTTPRequest.remote_ip` is still always an IP-style address
+ sockets. ``HTTPRequest.remote_ip`` is still always an IP-style address
(fake data is used for non-IP sockets)
* Extra data at the end of multipart form bodies is now ignored, which fixes
a compatibility problem with an iOS HTTP client library.
* `.HTTPServer` now takes a ``protocol`` keyword argument which can be set
to ``https`` if the server is behind an SSL-decoding proxy that does not
set any supported X-headers.
-* `tornado.httpserver.HTTPConnection` now has a ``set_close_callback``
+* ``tornado.httpserver.HTTPConnection`` now has a ``set_close_callback``
method that should be used instead of reaching into its ``stream``
attribute.
* Empty HTTP request arguments are no longer ignored. This applies to
HTTP 1.0 connections that explicitly pass ``Connection: keep-alive``.
* The ``Connection: keep-alive`` check for HTTP 1.0 connections is now
case-insensitive.
-* The `str` and `repr` of `tornado.httpserver.HTTPRequest` no longer
+* The `str` and `repr` of ``tornado.httpserver.HTTPRequest`` no longer
include the request body, reducing log spam on errors (and potential
exposure/retention of private data).
individual aspects of debug mode.
* New methods `.RequestHandler.get_query_argument` and
`.RequestHandler.get_body_argument` and new attributes
- `.HTTPRequest.query_arguments` and `.HTTPRequest.body_arguments` allow access
+ ``HTTPRequest.query_arguments`` and ``HTTPRequest.body_arguments`` allow access
to arguments without intermingling those from the query string with those
from the request body.
* `.RequestHandler.decode_argument` and related methods now raise
.. automethod:: RequestHandler.decode_argument
.. attribute:: RequestHandler.request
- The `tornado.httpserver.HTTPRequest` object containing additional
+ The `tornado.httputil.HTTPServerRequest` object containing additional
request parameters including e.g. headers and body data.
.. attribute:: RequestHandler.path_args
class except to start a server at the beginning of the process
(and even that is often done indirectly via `tornado.web.Application.listen`).
-This module also defines the `HTTPRequest` class which is exposed via
-`tornado.web.RequestHandler.request`.
+.. versionchanged:: 3.3
+
+ The ``HTTPRequest`` class that used to live in this module has been moved
+ to `tornado.httputil.HTTPServerRequest`. The old name remains as an alias.
"""
from __future__ import absolute_import, division, print_function, with_statement
A server is defined by a request callback that takes an HTTPRequest
instance as an argument and writes a valid HTTP response with
- `HTTPRequest.write`. `HTTPRequest.finish` finishes the request (but does
+ `.HTTPServerRequest.write`. `.HTTPServerRequest.finish` finishes the request (but does
not necessarily close the connection in the case of HTTP/1.1 keep-alive
requests). A simple example server that echoes back the URI you
requested::
# License for the specific language governing permissions and limitations
# under the License.
-"""HTTP utility code shared by clients and servers."""
+"""HTTP utility code shared by clients and servers.
+
+This module also defines the `HTTPServerRequest` class which is exposed
+via `tornado.web.RequestHandler.request`.
+"""
from __future__ import absolute_import, division, print_function, with_statement
@property
def cookies(self):
- """An alias for `self.request.cookies <.httpserver.HTTPRequest.cookies>`."""
+ """An alias for `self.request.cookies <.httputil.HTTPServerRequest.cookies>`."""
return self.request.cookies
def get_cookie(self, name, default=None):
"""A `RequestHandler` that wraps another HTTP server callback.
The fallback is a callable object that accepts an
- `~.httpserver.HTTPRequest`, such as an `Application` or
+ `~.httputil.HTTPServerRequest`, such as an `Application` or
`tornado.wsgi.WSGIContainer`. This is most useful to use both
Tornado ``RequestHandlers`` and WSGI in the same server. Typical
usage::
class HTTPRequest(object):
- """Mimics `tornado.httpserver.HTTPRequest` for WSGI applications."""
+ """Mimics `tornado.httputil.HTTPServerRequest` for WSGI applications."""
def __init__(self, environ):
"""Parses the given WSGI environment to construct the request."""
self.method = environ["REQUEST_METHOD"]
@staticmethod
def environ(request):
- """Converts a `tornado.httpserver.HTTPRequest` to a WSGI environment.
+ """Converts a `tornado.httputil.HTTPServerRequest` to a WSGI environment.
"""
hostport = request.host.split(":")
if len(hostport) == 2: