class documentation

class BaseRequest(object):

Known subclasses: bottle.LocalRequest

View In Hierarchy

A wrapper for WSGI environment dictionaries that adds a lot of convenient access methods and properties. Most of them are read-only.

Adding new attributes to a request actually adds them to the environ dictionary (as 'bottle.request.ext.<name>'). This is the recommended way to store and access request-specific data.

Method copy Return a new Request with a shallow environ copy.
Method get​_cookie No summary
Method get​_header Return the value of a request header, or a given default value.
Method path​_shift Shift path segments from path to script_name and vice versa.
Constant MEMFILE​_MAX Undocumented
Instance Variable environ Undocumented
Method __delitem__ Undocumented
Method __getattr__ Search in self.environ for additional user defined attributes.
Method __getitem__ Undocumented
Method __init__ Wrap a WSGI environ dictionary.
Method __iter__ Undocumented
Method __len__ Undocumented
Method __repr__ Undocumented
Method __setattr__ Undocumented
Method __setitem__ Change an environ value and clear all caches that depend on it.
Method ​_get​_body​_string read body until content-length or MEMFILE_MAX into a string. Raise HTTPError(413) on requests that are to large.
Method ​_iter​_body Undocumented
Method ​_iter​_chunked Undocumented
Method get Undocumented
Method keys Undocumented
Class Variable __slots__ Undocumented
Property ​_body Undocumented
Property app Bottle application handling this request.
Property auth No summary
Property body No summary
Property chunked True if Chunked transfer encoding was.
Property content​_length The request body length as an integer. The client is responsible to set this header. Otherwise, the real length of the body is unknown and -1 is returned. In this case, body will be empty.
Property content​_type The Content-Type header as a lowercase-string (default: empty).
Property cookies Cookies parsed into a FormsDict. Signed cookies are NOT decoded. Use get_cookie if you expect signed cookies.
Property files File uploads parsed from multipart/form-data encoded POST or PUT request body. The values are instances of FileUpload.
Property forms No summary
Property fullpath Request path including script_name (if present).
Property headers A WSGIHeaderDict that provides case-insensitive access to HTTP request headers.
Property is​_ajax Alias for is_xhr. "Ajax" is not the right term.
Property is​_xhr True if the request was triggered by a XMLHttpRequest. This only works with JavaScript libraries that support the X-Requested-With header (most of the popular libraries do).
Property json No summary
Property method The REQUEST_METHOD value as an uppercase string.
Property params A FormsDict with the combined values of query and forms. File uploads are stored in files.
Property path The value of PATH_INFO with exactly one prefixed slash (to fix broken clients and avoid the "empty path" edge case).
Property POST The values of forms and files combined into a single FormsDict. Values are either strings (form values) or instances of cgi.FieldStorage (file uploads).
Property query No summary
Property query​_string The raw query part of the URL (everything in between ? and #) as a string.
Property remote​_addr The client IP as a string. Note that this information can be forged by malicious clients.
Property remote​_route No summary
Property route The bottle Route object that matches this request.
Property script​_name No summary
Property url No summary
Property url​_args The arguments extracted from the URL.
Property urlparts No summary
def copy(self):
Return a new Request with a shallow environ copy.
def get_cookie(self, key, default=None, secret=None):
Return the content of a cookie. To read a Signed Cookie, the secret must match the one used to create the cookie (see BaseResponse.set_cookie). If anything goes wrong (missing cookie or wrong signature), return a default value.
def get_header(self, name, default=None):
Return the value of a request header, or a given default value.
def path_shift(self, shift=1):
Shift path segments from path to script_name and
vice versa.
Parameters
shiftThe number of path segments to shift. May be negative to change the shift direction. (default: 1)
MEMFILE_MAX: int =

Undocumented

Value
102400
environ =
overridden in bottle.LocalRequest

Undocumented

def __delitem__(self, key):

Undocumented

def __getattr__(self, name):
Search in self.environ for additional user defined attributes.
def __getitem__(self, key):

Undocumented

def __init__(self, environ=None):
Wrap a WSGI environ dictionary.
def __iter__(self):

Undocumented

def __len__(self):

Undocumented

def __repr__(self):

Undocumented

def __setattr__(self, name, value):

Undocumented

def __setitem__(self, key, value):
Change an environ value and clear all caches that depend on it.
def _get_body_string(self):
read body until content-length or MEMFILE_MAX into a string. Raise HTTPError(413) on requests that are to large.
def _iter_body(self, read, bufsize):

Undocumented

def _iter_chunked(self, read, bufsize):

Undocumented

def get(self, value, default=None):

Undocumented

def keys(self):

Undocumented

__slots__: str =

Undocumented

@DictProperty('environ', 'bottle.request.body', read_only=True)
_body =

Undocumented

@DictProperty('environ', 'bottle.app', read_only=True)
app =
Bottle application handling this request.
@property
auth =
HTTP authentication data as a (user, password) tuple. This implementation currently supports basic (not digest) authentication only. If the authentication happened at a higher level (e.g. in the front web-server or a middleware), the password field is None, but the user field is looked up from the REMOTE_USER environ variable. On any errors, None is returned.
@property
body =
The HTTP request body as a seek-able file-like object. Depending on MEMFILE_MAX, this is either a temporary file or a io.BytesIO instance. Accessing this property for the first time reads and replaces the wsgi.input environ variable. Subsequent accesses just do a seek(0) on the file object.
@property
chunked =
True if Chunked transfer encoding was.
@property
content_length =
The request body length as an integer. The client is responsible to set this header. Otherwise, the real length of the body is unknown and -1 is returned. In this case, body will be empty.
@property
content_type =
The Content-Type header as a lowercase-string (default: empty).
@DictProperty('environ', 'bottle.request.cookies', read_only=True)
cookies =
Cookies parsed into a FormsDict. Signed cookies are NOT decoded. Use get_cookie if you expect signed cookies.
@DictProperty('environ', 'bottle.request.files', read_only=True)
files =
File uploads parsed from multipart/form-data encoded POST or PUT request body. The values are instances of FileUpload.
@DictProperty('environ', 'bottle.request.forms', read_only=True)
forms =
Form values parsed from an url-encoded or multipart/form-data encoded POST or PUT request body. The result is returned as a FormsDict. All keys and values are strings. File uploads are stored separately in files.
@property
fullpath =
Request path including script_name (if present).
@DictProperty('environ', 'bottle.request.headers', read_only=True)
headers =
A WSGIHeaderDict that provides case-insensitive access to HTTP request headers.
@property
is_ajax =
Alias for is_xhr. "Ajax" is not the right term.
@property
is_xhr =
True if the request was triggered by a XMLHttpRequest. This only works with JavaScript libraries that support the X-Requested-With header (most of the popular libraries do).
@DictProperty('environ', 'bottle.request.json', read_only=True)
json =
If the Content-Type header is application/json, this property holds the parsed content of the request body. Only requests smaller than MEMFILE_MAX are processed to avoid memory exhaustion.
@property
method =
The REQUEST_METHOD value as an uppercase string.
@DictProperty('environ', 'bottle.request.params', read_only=True)
params =
A FormsDict with the combined values of query and forms. File uploads are stored in files.
@property
path =
The value of PATH_INFO with exactly one prefixed slash (to fix broken clients and avoid the "empty path" edge case).
@DictProperty('environ', 'bottle.request.post', read_only=True)
POST =
The values of forms and files combined into a single FormsDict. Values are either strings (form values) or instances of cgi.FieldStorage (file uploads).
@DictProperty('environ', 'bottle.request.query', read_only=True)
query =
The query_string parsed into a FormsDict. These values are sometimes called "URL arguments" or "GET parameters", but not to be confused with "URL wildcards" as they are provided by the Router.
@property
query_string =
The raw query part of the URL (everything in between ? and #) as a string.
@property
remote_addr =
The client IP as a string. Note that this information can be forged by malicious clients.
@property
remote_route =
A list of all IPs that were involved in this request, starting with the client IP and followed by zero or more proxies. This does only work if all proxies support the `X-Forwarded-For header. Note that this information can be forged by malicious clients.
@DictProperty('environ', 'bottle.route', read_only=True)
route =
The bottle Route object that matches this request.
@property
script_name =
The initial portion of the URL's path that was removed by a higher level (server or routing middleware) before the application was called. This script path is returned with leading and tailing slashes.
@property
url =
The full request URI including hostname and scheme. If your app lives behind a reverse proxy or load balancer and you get confusing results, make sure that the X-Forwarded-Host header is set correctly.
@DictProperty('environ', 'route.url_args', read_only=True)
url_args =
The arguments extracted from the URL.
@DictProperty('environ', 'bottle.request.urlparts', read_only=True)
urlparts =
The url string as an urlparse.SplitResult tuple. The tuple contains (scheme, host, path, query_string and fragment), but the fragment is always empty because it is not visible to the server.