class documentation

class BaseRequest(object): (source)

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 __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 copy Return a new :class:`Request` with a shallow :attr:`environ` copy.
Method get Undocumented
Method get_cookie Return the content of a cookie. To read a `Signed Cookie`, the `secret` must match the one used to create the cookie (see :meth:`BaseResponse.set_cookie`). If anything goes wrong (missing cookie or wrong signature), return a default value...
Method get_header Return the value of a request header, or a given default value.
Method keys Undocumented
Method path_shift Shift path segments from :attr:`path` to :attr:`script_name` and vice versa.
Constant MEMFILE_MAX Undocumented
Class Variable __slots__ Undocumented
Instance Variable environ Undocumented
Property 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...
Property body The HTTP request body as a seek-able file-like object. Depending on :attr:`MEMFILE_MAX`, this is either a temporary file or a :class:`io.BytesIO` instance. Accessing this property for the first time reads and replaces the ``wsgi...
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, :attr:`body` will be empty.
Property content_type The Content-Type header as a lowercase-string (default: empty).
Property cookies Cookies parsed into a :class:`FormsDict`. Signed cookies are NOT decoded. Use :meth:`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 :class:`FileUpload`.
Property forms Form values parsed from an `url-encoded` or `multipart/form-data` encoded POST or PUT request body. The result is returned as a :class:`FormsDict`. All keys and values are strings. File uploads are stored separately in :attr:`files`...
Property fullpath Request path including :attr:`script_name` (if present).
Property headers A :class:`WSGIHeaderDict` that provides case-insensitive access to HTTP request headers.
Property is_ajax Alias for :attr:`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 If the ``Content-Type`` header is ``application/json``, this property holds the parsed content of the request body. Only requests smaller than :attr:`MEMFILE_MAX` are processed to avoid memory exhaustion...
Property method The ``REQUEST_METHOD`` value as an uppercase string.
Property params A :class:`FormsDict` with the combined values of :attr:`query` and :attr:`forms`. File uploads are stored in :attr:`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 :attr:`forms` and :attr:`files` combined into a single :class:`FormsDict`. Values are either strings (form values) or instances of :class:`cgi.FieldStorage` (file uploads).
Property query The :attr:`query_string` parsed into a :class:`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 :class:`Router`...
Property query_string The raw :attr:`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...
Property route The bottle :class:`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...
Property url_args The arguments extracted from the URL.
Property urlparts The :attr:`url` string as an :class:`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...
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
Property _body Undocumented
def __delitem__(self, key): (source)

Undocumented

def __getattr__(self, name): (source)

Search in self.environ for additional user defined attributes.

def __getitem__(self, key): (source)

Undocumented

def __init__(self, environ=None): (source)

Wrap a WSGI environ dictionary.

def __iter__(self): (source)

Undocumented

def __len__(self): (source)

Undocumented

def __repr__(self): (source)

Undocumented

def __setattr__(self, name, value): (source)

Undocumented

def __setitem__(self, key, value): (source)

Change an environ value and clear all caches that depend on it.

def copy(self): (source)

Return a new :class:`Request` with a shallow :attr:`environ` copy.

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

Undocumented

def get_cookie(self, key, default=None, secret=None): (source)

Return the content of a cookie. To read a `Signed Cookie`, the `secret` must match the one used to create the cookie (see :meth:`BaseResponse.set_cookie`). If anything goes wrong (missing cookie or wrong signature), return a default value.

def get_header(self, name, default=None): (source)

Return the value of a request header, or a given default value.

def keys(self): (source)

Undocumented

def path_shift(self, shift=1): (source)

Shift path segments from :attr:`path` to :attr:`script_name` and vice versa. :param shift: The number of path segments to shift. May be negative to change the shift direction. (default: 1)

MEMFILE_MAX: int = (source)

Undocumented

Value
102400
__slots__: str = (source)

Undocumented

overridden in bottle.LocalRequest

Undocumented

@DictProperty('environ', 'bottle.app', read_only=True)
app = (source)

Bottle application handling this request.

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.

The HTTP request body as a seek-able file-like object. Depending on :attr:`MEMFILE_MAX`, this is either a temporary file or a :class:`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.

True if Chunked transfer encoding was.

@property
content_length = (source)

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, :attr:`body` will be empty.

@property
content_type = (source)

The Content-Type header as a lowercase-string (default: empty).

@DictProperty('environ', 'bottle.request.cookies', read_only=True)
cookies = (source)

Cookies parsed into a :class:`FormsDict`. Signed cookies are NOT decoded. Use :meth:`get_cookie` if you expect signed cookies.

@DictProperty('environ', 'bottle.request.files', read_only=True)
files = (source)

File uploads parsed from `multipart/form-data` encoded POST or PUT request body. The values are instances of :class:`FileUpload`.

@DictProperty('environ', 'bottle.request.forms', read_only=True)
forms = (source)

Form values parsed from an `url-encoded` or `multipart/form-data` encoded POST or PUT request body. The result is returned as a :class:`FormsDict`. All keys and values are strings. File uploads are stored separately in :attr:`files`.

Request path including :attr:`script_name` (if present).

@DictProperty('environ', 'bottle.request.headers', read_only=True)
headers = (source)

A :class:`WSGIHeaderDict` that provides case-insensitive access to HTTP request headers.

Alias for :attr:`is_xhr`. "Ajax" is not the right term.

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 = (source)

If the ``Content-Type`` header is ``application/json``, this property holds the parsed content of the request body. Only requests smaller than :attr:`MEMFILE_MAX` are processed to avoid memory exhaustion.

The ``REQUEST_METHOD`` value as an uppercase string.

@DictProperty('environ', 'bottle.request.params', read_only=True)
params = (source)

A :class:`FormsDict` with the combined values of :attr:`query` and :attr:`forms`. File uploads are stored in :attr:`files`.

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 = (source)

The values of :attr:`forms` and :attr:`files` combined into a single :class:`FormsDict`. Values are either strings (form values) or instances of :class:`cgi.FieldStorage` (file uploads).

@DictProperty('environ', 'bottle.request.query', read_only=True)
query = (source)

The :attr:`query_string` parsed into a :class:`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 :class:`Router`.

@property
query_string = (source)

The raw :attr:`query` part of the URL (everything in between ``?`` and ``#``) as a string.

@property
remote_addr = (source)

The client IP as a string. Note that this information can be forged by malicious clients.

@property
remote_route = (source)

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 = (source)

The bottle :class:`Route` object that matches this request.

@property
script_name = (source)

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.

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 = (source)

The arguments extracted from the URL.

@DictProperty('environ', 'bottle.request.urlparts', read_only=True)
urlparts = (source)

The :attr:`url` string as an :class:`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.

def _get_body_string(self): (source)

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): (source)

Undocumented

def _iter_chunked(self, read, bufsize): (source)

Undocumented

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

Undocumented