Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

See ApplicationReference for other objects and interfaces.

Response Object

This page describes the attributes of the cherrypy response object. For an overview of request phases, see RequestObject.

body

The entity to send in the HTTP response. This is set to the return value of your page handler. It should always be an iterable.

check_timeout

Called at various points by the core (including a monitor thread in the Engine) to verify that now - response.time < response.timeout. If it is not, response.timed_out is set, and the core will raise TimeoutError? at the next opportunity.

collapse_body

When streaming the response body instead of buffering, calling this method buffers the stream so that it can be analyzed and modified before writing it out to the client.

A SimpleCookie? instance from the standard library's Cookie module. It contains the outgoing cookie values.

finalize

A method used by the core to validate the response status, transform response.headers into response.header_list, and check correct Content-Length.

header_list

A list of response header (key, value) pairs. These are set automatically during the finalize phase from response.headers and response.cookie.

headers

A dictionary containing the headers of the response. You may set values in this dict anytime before the finalize phase, after which CherryPy switches to using header_list (so changes to 'headers' effectively do nothing). The keys of this dict are automatically title-cased (e.g., "Content-Type"), but you can use any case to interact with it (e.g. headers['content-type'] is just fine). Since it's a dictionary, no duplicates are allowed. If you encounter the extremely rare case where duplicate headers (or the case of header keys, or the order of headers) are important, use header_list instead.

status

An HTTP status, either an int (code only) or string (code and reason-phrase). During the finalize phase, this will be coerced to a string (and given a reason-phrase if not provided).

stream

If True, tells CherryPy to not buffer the response body.

time

The time the response object was created, as a floating point number expressed in seconds since the epoch, in UTC.

timed_out

A boolean indicating whether the response has timed out. If True, the core will raise TimeoutError? at the next opportunity.

timeout

The number of seconds to allow (from response.time) before raising TimeoutError?.

Older versions

2.2

replace this with this
response.cookieresponse.simple_cookie
  • response.version: This attribute is a Version object, representing the HTTP protocol version of the response. This is not necessarily the value that will be written in the response! Instead, it should be used to determine which features are available for the response. For example, an HTTP server may send an HTTP/1.1 response even though the client is known to only understand HTTP/1.0 the response.version will be set to Version("1.0") to inform you of this, so that you (and CherryPy) can restrict the response to HTTP/1.0 features only.

Hosted by WebFaction

Log in as guest/cpguest to create tickets