An HTTP request.
This object represents the metadata of an HTTP request message; that is, it contains attributes which describe the environment in which the request URL, headers, and body were sent (if you want tools to interpret the headers and body, those are elsewhere, mostly in Tools). This ‘metadata’ consists of socket data, transport characteristics, and the Request-Line. This object also contains data regarding the configuration in effect for the given URL, and the execution plan for generating a response.
If the request Content-Type is ‘application/x-www-form-urlencoded’ or multipart, this will be a dict of the params pulled from the entity body; that is, it will be the portion of request.params that come from the message body (sometimes called “POST params”, although they can be sent with various HTTP method verbs). This value is set between the ‘before_request_body’ and ‘before_handler’ hooks (assuming that process_request_body is True).
Deprecated in 3.2, will be removed for 3.3 in favor of request.body.params.
The object which looks up the ‘page handler’ callable and collects config for the current request based on the path_info, other request attributes, and the application architecture. The core calls the dispatcher as early as possible, passing it a ‘path_info’ argument.
The default dispatcher discovers the page handler by matching path_info to a hierarchical arrangement of objects, starting at request.app.root. See help(cherrypy.dispatch) for more information.
A dict of {error code: response filename or callable} pairs.
The error code must be an int representing a given HTTP error code, or the string ‘default’, which will be used if no matching entry is found for a given numeric code.
If a filename is provided, the file should contain a Python string- formatting template, and can expect by default to receive format values with the mapping keys %(status)s, %(message)s, %(traceback)s, and %(version)s. The set of format mappings can be extended by overriding HTTPError.set_response.
If a callable is provided, it will be called by default with keyword arguments ‘status’, ‘message’, ‘traceback’, and ‘version’, as for a string-formatting template. The callable must return a string or iterable of strings which will be set to response.body. It may also override headers or perform any other processing.
If no entry is given for an error code, and no ‘default’ entry exists, a default template will be used.
If the request included an entity (body), it will be available as a stream in this attribute. However, the rfile will normally be read for you between the ‘before_request_body’ hook and the ‘before_handler’ hook, and the resulting string is placed into either request.params or the request.body attribute.
You may disable the automatic consumption of the rfile by setting request.process_request_body to False, either in config for the desired path, or in an ‘on_start_resource’ or ‘before_request_body’ hook.
WARNING: In almost every case, you should not attempt to read from the rfile stream after CherryPy’s automatic mechanism has read it. If you turn off the automatic parsing of rfile, you should read exactly the number of bytes specified in request.headers[‘Content-Length’]. Ignoring either of these warnings may result in a hung request thread or in corruption of the next (pipelined) request.
Process the Request. (Core)
method, path, query_string, and req_protocol should be pulled directly from the Request-Line (e.g. “GET /path?key=val HTTP/1.0”).
When run() is done, the returned object should have 3 attributes:
- status, e.g. “200 OK”
- header_list, a list of (name, value) tuples
- body, an iterable yielding strings
Consumer code (HTTP servers) should then access these response attributes to build the outbound stream.
The ‘mount point’ of the application which is handling this request.
This attribute MUST NOT end in a slash. If the script_name refers to the root of the URI, it MUST be an empty string (not “/”).
An HTTP Response, including status, headers, and body.
If now > self.time + self.timeout, set self.timed_out.
This purposefully sets a flag, rather than raising an error, so that a monitor thread can interrupt the Response thread.
A dict-like object containing the response headers. Keys are header names (in Title-Case format); however, you may get and set them in a case-insensitive manner. That is, headers[‘Content-Type’] and headers[‘content-type’] refer to the same value. Values are header values (decoded according to RFC 2047 if necessary).
See also
classes HeaderMap, HeaderElement
A callback and its metadata: failsafe, priority, and kwargs.