rhino.request
class Request
Represents an HTTP request built from a WSGI environment.
Class variables:
When True
(the default), Request.input
returns environ['wsgi.input']
wrapped in WsgiInput
, to make it safe to call read()
on it without providing the content length. This is required for servers like wsgiref.simple_server
, which is also used by Rhino.mapper.start_server()
.
Some WSGI servers (e.g. gevent.pywsgi
) provide a safe wsgi.input
that also supports chunked encoding (a.k.a streamed uploads). To be able to benefit from this functionality, wrap_wsgi_input
needs to be set to False
. Alternatively, the original input file can always be found in Request.environ['wsgi.input']
.
__init__(environ)
body
Reads and returns the entire request body.
On first access, reads content_length
bytes from input
and stores the result on the request instance. On subsequent access, returns the cached value.
content_length
The value of the Content-Length header as an integer, or None
content_type
The value of the Content-Type header, or None
form
Reads the request body and tries to parse it as a web form.
Parsing is done using the stdlib's cgi.FieldStorage
class which supports multipart forms (file uploads). Returns a QueryDict
instance holding the form fields. Uploaded files are represented as form fields with a 'filename' attribute.
input
Returns a file-like object representing the request body.
method
The HTTP request method (verb).
path_info
The PATH_INFO environment key as a unicode string.
query
A QueryDict instance holding the query parameters (QUERY_STRING).
remote_addr
The REMOTE_ADDR environment key
remote_port
The client's port number as an integer, or None (REMOTE_PORT).
routing_args
Returns named parameters extracted from the URL during routing.
scheme
The URL scheme, usually 'http' or 'https' (wsgi.url_scheme).
script_name
The SCRIPT_NAME environment key as a unicode string.
server_name
The SERVER_NAME environment key
server_port
The server's port number as an integer, or None (SERVER_PORT).
server_protocol
The SERVER_PROTOCOL environment key
url
The reconstructed request URL (absolute).
url_for(*args, **kw)
Build the URL for a target route.
The target is the first positional argument, and can be any valid target for Mapper.path
, which will be looked up on the current mapper instance and used to build the URL for that route. Additionally, it can be one of:
Special keyword arguments:
_query
_relative
All other keyword arguments are treated as parameters for the URL template.
class RequestHeaders
A dictionary-like object to access request headers.
Keys are case-insensitive. Accessing a header that is not present returns None instead of raising KeyError.
__init__(environ)
class QueryDict
A dictionary-like object to access query parameters.
Accessing a key returns the first value for that key. The keys(), values() and items() methods will return a key/value multiple times, if it is present multiple times in the query string.
The get_all() method can be used to return all values for a given key.
__init__(items)
get_all(key)
Return a list of values for the given key.
class WsgiInput
Represents a WSGI input filehandle that is safe to use read() on
__init__(rfile, content_length=None)