A single HTTP request. Instances of this class are created by app automatically; you don’t need to do that yourself.
The HTTP version the client used as a (major, minor)
tuple.
The HTTP method used by the client, e.g. GET
or POST
.
The path requested by the client. Relative to the current routing module (see route.dir.)
Additional HTTP headers as a struct.Headers.
The request body as a bytes
object.
The instance of the application that handled this requests, i.e. the thing created with app.
The top-level handler this request was passed to (the one you created an instance of app with.)
The asyncio event loop everything is running in.
A logging.Logger named dogeweb
.
Parsed values of various Accept
headers.
accept.mime
– Accept
accept.charset
– Accept-Charset
accept.language
– Accept-Language
accept.encoding
– Accept-Encoding
All of these are represented by struct.Accept objects. MIME types, charsets, or whatever not specified in the request will have a quality of 0.
All cookies from this request as a semi-immutable dict
.
Create a new cookie. Note that you still have to create a Response
with
the appropriate header; this method returns a singleton list containing that header.
handler = req ->
headers = req.cookies.set 'visited' 'true'
headers += req.cookies.set 'last_ts' $ str time!
# ...
200, headers, more_headers, ..., '<!doctype html><html>...</html>'
By default, a cookie is module-local, i.e. path-restricted to the current
routing module and its submodules (see route.dir). Override
path
if that’s not desired.
headers = req.cookies.set 'visited_module' 'yes'
headers += req.cookies.set 'visited_site' 'true' path: '/'
maxage
is the expiration time in seconds; 0 (the default) means
the cookie is valid until the browser window is closed.
When reading cookies, local ones have priority over global ones. If the above code
used the same name for both cookies, requests to the same module would always
contain yes
while requests to other modules would have that cookie set to true
.
Remove a cookie (by setting its max-age
to 0.) The path should match
the one used when creating that cookie exactly. By default, this removes
a cookie belonging to the current module. Just like set
, returns
a singleton list with a header to pass to the client.
del
is a reserved name in Python, so there’s an alias available, rem
.
Form fields passed through the URL (the part after ?
) as a struct.MultiDict.
Form fields passed through the request body. This includes files, too.
Same as form
, but only top-level files are included. Removes the need for some
type-checking.
Whether this request was made through XmlHttpRequest
(aka AJAX).
Whether the client expects JSON instead of HTML. Useful for building APIs.
The IP address of the client as a string.
The requested path. This one is absolute, unlike path
, which is relative to the module.
The difference between fullpath
and `path.
Given the name of a route (in a syntax similar to Python relative imports) and some keyword arguments, construct an URL that points to that route.
For example, given this route structure:
/hello/ -> modhello (module) /world/ -> world /user/ -> user / -> main (module) / -> root /login/ -> login /u/<name>/ -> userinfo
Suppose the user has requested /hello/user/
, meaning the current route’s path
is modhello.user
and the currently used module is modhello
. Here’s what
different calls to url_for
would return:
url_for '.world' -> '/hello/world/'
url_for '..modhello.user' -> '/hello/user/'
url_for '..main.root' -> '/'
url_for 'main.login' -> '/login/'
url_for 'main.userinfo' name: 'spam' -> '/u/spam/'
The following methods do not use any info from the request; they’re shortcuts.
Same as response.abort.
Same as response.redirect.
Same as response.static.
Same as response.jsonify.