Response

Represents a WSGI response


Attributes

a content_length

<Converted <Proxy for header Content-Length> int>

a pragma

<Proxy for header Pragma>

a vary

<Converted <Proxy for header Vary> list>

a location

Retrieve the Location header of the response, or None if there is no header. If the header is not absolute and this response is associated with a request, make the header absolute.

For more information see section 14.30.

a accept_ranges

<Proxy for header Accept-Ranges>

a server

<Proxy for header Server>

a body

The body of the response, as a str. This will read in the entire app_iter if necessary.

a status_int

The status as an integer

a etag

<Proxy for header ETag>

a content_range

<Converted <Proxy for header Content-Range> ContentRange object>

a content_md5

<Proxy for header Content-MD5>

a last_modified

<Converted <Proxy for header Last-Modified> HTTP date>

a unicode_body

Get/set the unicode value of the body (using the charset of the Content-Type)

a retry_after

<Converted <Proxy for header Retry-After> HTTP date or delta seconds>

a content_language

<Converted <Proxy for header Content-Language> list>

a content_location

<Proxy for header Content-Location>

a default_charset

'UTF-8'

a default_content_type

'text/html'

a app_iter

Returns the app_iter of the response.

If body was set, this will create an app_iter from that body (a single-item list)

a content_encoding

<Proxy for header Content-Encoding>

a cache_control

Get/set/modify the Cache-Control header (section 14.9)

a content_type_params

Returns a dictionary of all the parameters in the content type.

a content_type

Get/set the Content-Type header (or None), without the charset or any parameters.

If you include parameters (or ; at all) when setting the content_type, any existing parameters will be deleted; otherwise they will be preserved.

a default_conditional_response

False

a headers

The headers in a dictionary-like object

a body_file

Returns a file-like object that can be used to write to the body. If you passed in a list app_iter, that app_iter will be modified by writes.

a charset

Get/set the charset (in the Content-Type)

a status

The status string

a expires

<Converted <Proxy for header Expires> HTTP date>

a date

<Converted <Proxy for header Date> HTTP date>

a age

<Converted <Proxy for header Age> int>

a request

Return the request associated with this response if any.

a headerlist

The list of response headers

a environ

Get/set the request environ associated with this response, if any.

a allow

<Converted <Proxy for header Allow> list>

Methods

f __init__(self, body=None, status='200 OK', headerlist=None, app_iter=None, request=None, content_type=None, conditional_response=(No Default), **kw) ...

f write(self, text) ...

f set_cookie(self, key, value='', max_age=None, path='/', domain=None, secure=None, httponly=False, version=None, comment=None, expires=None) ...

Set (add) a cookie for the response

f delete_cookie(self, key, path='/', domain=None) ...

Delete a cookie from the client. Note that path and domain must match how the cookie was originally set.

This sets the cookie to the empty string, and max_age=0 so that it should expire immediately.

f unset_cookie(self, key) ...

Unset a cookie with the given name (remove it from the response). If there are multiple cookies (e.g., two cookies with the same name and different paths or domains), all such cookies will be deleted.

f cache_expires(self, seconds=0, **kw) ...

Set expiration on this request. This sets the response to expire in the given seconds, and any other attributes are used for cache_control (e.g., private=True, etc).

f encode_content(self, encoding='gzip') ...

Encode the content with the given encoding (only gzip and identity are supported).

f decode_content(self) ...

f md5_etag(self, body=None) ...

Generate an etag for the response object using an MD5 hash of the body (the body parameter, or self.body if not given)

Sets self.etag

f __call__(self, environ, start_response) ...

WSGI application interface

f conditional_response_app(self, environ, start_response) ...

Like the normal __call__ interface, but checks conditional headers:

f app_iter_range(self, start, stop) ...

Return a new app_iter built from the response app_iter, that serves up only the given start:stop range.

See the source for more information.