Request¶
Request object.
Interface
¶
- class wptserve.request.Authentication(headers)¶
Object for dealing with HTTP Authentication
- username¶
The username supplied in the HTTP Authorization header, or None
- password¶
The password supplied in the HTTP Authorization header, or None
Both attributes are binary strings (str in Py2, bytes in Py3), since RFC7617 Section 2.1 does not specify the encoding for username & password (as long it’s compatible with ASCII). UTF-8 should be a relatively safe choice if callers need to decode them as most browsers use it.
- class wptserve.request.BinaryCookieParser(input=None)¶
A subclass of BaseCookie that returns values in binary strings
This is not intended to store the cookies; use Cookies instead.
- load(rawdata)¶
Load cookies from a binary string.
This overrides and calls BaseCookie.load. Unlike BaseCookie.load, it does not accept dictionaries.
- value_decode(val)¶
Decode value from network to (real_value, coded_value).
Override BaseCookie.value_decode.
- value_encode(val)¶
real_value, coded_value = value_encode(VALUE) Called prior to setting a cookie’s value from the dictionary representation. The VALUE is the value being assigned. Override this function to modify the behavior of cookies.
- class wptserve.request.CookieValue(morsel)¶
Representation of cookies.
Note that cookies are considered read-only and the string value of the cookie will not change if you update the field values. However this is not enforced.
- key¶
The name of the cookie.
- value¶
The value of the cookie
- expires¶
The expiry date of the cookie
- path¶
The path of the cookie
- comment¶
The comment of the cookie.
- domain¶
The domain with which the cookie is associated
- max_age¶
The max-age value of the cookie.
- secure¶
Whether the cookie is marked as secure
- httponly¶
Whether the cookie is marked as httponly
- class wptserve.request.Cookies¶
MultiDict specialised for Cookie values
Keys are binary strings and values are CookieValue objects.
- class wptserve.request.H2Request(request_handler)¶
- class wptserve.request.MultiDict¶
Dictionary type that holds multiple values for each key
- first(key, default=<object object>)¶
Get the first value with a given key
- Parameters:
key – The key to lookup
default – The default to return if key is not found (throws if nothing is specified)
- classmethod from_field_storage(fs)¶
Construct a MultiDict from a cgi.FieldStorage
Note that all keys and values are binary strings.
- get(key, default=None)¶
Get the first value with a given key
- Parameters:
key – The key to lookup
default – The default to return if key is not found (None by default)
- get_list(key)¶
Get all values with a given key as a list
- Parameters:
key – The key to lookup
- last(key, default=<object object>)¶
Get the last value with a given key
- Parameters:
key – The key to lookup
default – The default to return if key is not found (throws if nothing is specified)
- class wptserve.request.Request(request_handler)¶
Object representing a HTTP request.
- doc_root¶
The local directory to use as a base when resolving paths
- route_match¶
Regexp match object from matching the request path to the route selected for the request.
- client_address¶
Contains a tuple of the form (host, port) representing the client’s address.
- protocol_version¶
HTTP version specified in the request.
- method¶
HTTP method in the request.
- request_path¶
Request path as it appears in the HTTP request.
- url_base¶
The prefix part of the path; typically / unless the handler has a url_base set
- url¶
Absolute URL for the request.
- url_parts¶
Parts of the requested URL as obtained by urlparse.urlsplit(path)
- request_line¶
Raw request line
- headers¶
RequestHeaders object providing a dictionary-like representation of the request headers.
- raw_headers.
Dictionary of non-normalized request headers.
- body¶
Request body as a string
- raw_input¶
File-like object representing the body of the request.
- GET¶
MultiDict representing the parameters supplied with the request. Note that these may be present on non-GET requests; the name is chosen to be familiar to users of other systems such as PHP. Both keys and values are binary strings.
- POST¶
MultiDict representing the request body parameters. Most parameters are present as string values, but file uploads have file-like values. All string values (including keys) have binary type.
- cookies¶
A Cookies object representing cookies sent with the request with a dictionary-like interface.
- auth¶
An instance of Authentication with username and password properties representing any credentials supplied using HTTP authentication.
- server¶
Server object containing information about the server environment.
- class wptserve.request.RequestHeaders(items)¶
Read-only dictionary-like API for accessing request headers.
Unlike BaseHTTPRequestHandler.headers, this class always returns all headers with the same name (separated by commas). And it ensures all keys (i.e. names of headers) and values have binary type.
- get(key, default=None)¶
Get a string representing all headers with a particular value, with multiple headers separated by a comma. If no header is found return a default value
- Parameters:
key – The header name to look up (case-insensitive)
default – The value to return in the case of no match
- get_list(key, default=<object object>)¶
Get all the header values for a particular field name as a list