class documentation

class BaseResponse(object):

Known subclasses: bottle.HTTPResponse, bottle.LocalResponse

View In Hierarchy

Storage class for a response body as well as headers and cookies.

This class does support dict-like case-insensitive item-access to headers, but is NOT a dict. Most notably, iterating over a response yields parts of the body and not the headers.

Additional keyword arguments are added to the list of headers. Underscores in the header name are replaced with dashes.

Parameters
bodyThe response body as one of the supported types.
statusEither an HTTP status code (e.g. 200) or a status line including the reason phrase (e.g. '200 OK').
headersA dictionary or a list of name-value pairs.
Method add​_header Add an additional response header, not removing duplicates.
Method copy Returns a copy of self.
Method delete​_cookie Delete a cookie. Be sure to use the same domain and path settings as used to create the cookie.
Method get​_header Return the value of a previously defined header. If there is no header with that name, return a default value.
Method iter​_headers Yield (header, value) tuples, skipping headers that are not allowed with the current response status code.
Method set​_cookie Create a new cookie or replace an old one. If the secret parameter is set, create a Signed Cookie (described below).
Method set​_header Create a new response header, replacing any previously defined headers with the same name.
Class Variable content​_length Undocumented
Class Variable content​_type Undocumented
Class Variable expires Undocumented
Instance Variable status Undocumented
Method __contains__ Undocumented
Method __delitem__ Undocumented
Method __getitem__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __repr__ Undocumented
Method __setitem__ Undocumented
Method ​_get​_status Undocumented
Method ​_set​_status Undocumented
Method close Undocumented
Class Variable bad​_headers Undocumented
Class Variable default​_content​_type Undocumented
Class Variable default​_status Undocumented
Instance Variable ​_cookies Undocumented
Instance Variable ​_headers Undocumented
Instance Variable ​_status​_code Undocumented
Instance Variable ​_status​_line Undocumented
Instance Variable body Undocumented
Property charset Return the charset specified in the content-type header (default: utf8).
Property headerlist WSGI conform list of (header, value) tuples.
Property headers An instance of HeaderDict, a case-insensitive dict-like view on the response headers.
Property status​_code The HTTP status code as an integer (e.g. 404).
Property status​_line The HTTP status line as a string (e.g. 404 Not Found).
def add_header(self, name, value):
Add an additional response header, not removing duplicates.
def copy(self, cls=None):
Returns a copy of self.
def delete_cookie(self, key, **kwargs):
Delete a cookie. Be sure to use the same domain and path settings as used to create the cookie.
def get_header(self, name, default=None):
Return the value of a previously defined header. If there is no header with that name, return a default value.
def iter_headers(self):
Yield (header, value) tuples, skipping headers that are not allowed with the current response status code.
def set_cookie(self, name, value, secret=None, **options):

Create a new cookie or replace an old one. If the secret parameter is set, create a Signed Cookie (described below).

Additionally, this method accepts all RFC 2109 attributes that are supported by cookie.Morsel, including:

If neither expires nor max_age is set (default), the cookie will expire at the end of the browser session (as soon as the browser window is closed).

Signed cookies may store any pickle-able object and are cryptographically signed to prevent manipulation. Keep in mind that cookies are limited to 4kb in most browsers.

Warning: Signed cookies are not encrypted (the client can still see the content) and not copy-protected (the client can restore an old cookie). The main intention is to make pickling and unpickling save, not to store secret information at client side.

Parameters
namethe name of the cookie.
valuethe value of the cookie.
secreta signature key required for signed cookies.
**optionsUndocumented
max​_agemaximum age in seconds. (default: None)
expiresa datetime object or UNIX timestamp. (default: None)
domainthe domain that is allowed to read the cookie. (default: current domain)
pathlimits the cookie to a given path (default: current path)
securelimit the cookie to HTTPS connections (default: off).
httponlyprevents client-side javascript to read this cookie (default: off, requires Python 2.6 or newer).
def set_header(self, name, value):
Create a new response header, replacing any previously defined headers with the same name.
content_length =

Undocumented

content_type =

Undocumented

expires =

Undocumented

status =

Undocumented

def __contains__(self, name):

Undocumented

def __delitem__(self, name):

Undocumented

def __getitem__(self, name):

Undocumented

def __init__(self, body='', status=None, headers=None, **more_headers):
overridden in bottle.HTTPResponse

Undocumented

def __iter__(self):

Undocumented

def __repr__(self):

Undocumented

def __setitem__(self, name, value):

Undocumented

def _get_status(self):

Undocumented

def _set_status(self, status):

Undocumented

def close(self):

Undocumented

bad_headers =

Undocumented

default_content_type: str =

Undocumented

default_status: int =
overridden in bottle.HTTPError

Undocumented

_cookies =
overridden in bottle.LocalResponse

Undocumented

_headers: dict =
overridden in bottle.LocalResponse

Undocumented

_status_code =
overridden in bottle.LocalResponse

Undocumented

_status_line =
overridden in bottle.LocalResponse

Undocumented

body =
overridden in bottle.LocalResponse

Undocumented

@property
charset =
Return the charset specified in the content-type header (default: utf8).
@property
headerlist =
WSGI conform list of (header, value) tuples.
@property
headers =
An instance of HeaderDict, a case-insensitive dict-like view on the response headers.
@property
status_code =
The HTTP status code as an integer (e.g. 404).
@property
status_line =
The HTTP status line as a string (e.g. 404 Not Found).