Routing
Classes
RouteRule
RouteRule ( action , subject = None , stage : str = stages . REQUEST )
Represents a routing rule.
actions
Actions available for routing rules.
Values returned by actions:
* ``NEXT`` - continue to the next rule
* ``CONTINUE`` - stop scanning the internal routing table and run the request
* ``BREAK`` - stop scanning the internal routing table and close the request
* ``GOTO x`` - go to rule ``x``
stages
During the request cycle, various stages (aka chains) are processed.
Chains can be "recursive". A recursive chain can be called multiple times
in a request cycle.
ERROR
Applied as soon as an HTTP status code is generate. Recursive chain .
FINAL
Applied after the response has been sent to the client.
REQUEST
Applied before the request is passed to the plugin.
RESPONSE
Applied after the last response header has been generated (just before sending the body).
subjects
Routing subjects. These can be request's variables or other entities.
Note
Non-custom subjects can be pre-optimized (during startup)
and should be used for performance reasons.
A transformation is like a filter applied to the response
generated by your application.
Transformations can be chained (the output of a transformation will be the input of the following one)
and can completely overwrite response headers.
var_functions
Functions that can be applied to variables.
Routing
OptionsGroup
Routing subsystem.
You can use the internal routing subsystem to dynamically alter the way requests are handled.
name
Name to represent the group.
plugin
. plugin : bool | str = False
Indication this option group belongs to a plugin.
. header_add ( name : str , value : str )
Automatically add HTTP headers to response.
. header_collect (
name : str ,
target_var : str ,
pull : bool = False , # (1)!
)
Whether to remove header from response.
Store the specified response header in a request var
(optionally removing it from the response).
. header_remove ( value : str )
Automatically remove specified HTTP header from the response.
print_routing_rules
Print out supported routing rules (actions, transforms, etc.).
register_route
. register_route ( route_rules , label : str | None = None )
Registers a routing rule.
set_error_page
. set_error_page (
status : int , # (1)!
html_fpath : str , # (2)!
)
HTTP status code.
HTML page file path.
Add an error page (html) for managed 403, 404, 500 response.
set_error_pages
. set_error_pages (
codes_map : dict | None = None , # (1)!
common_prefix : Strpath = None , # (2)!
)
Status code mapped into an html filepath or
just a filename if common_prefix is used.
If not set, filename containing status code is presumed: 400.html, 500.html, etc.
Common path (prefix) for all files.
Add an error pages for managed 403, 404, 500 responses.
Shortcut for .set_error_page().
set_geoip_params
. set_geoip_params (
db_country : str | None = None ,
db_city : str | None = None
)
Sets GeoIP parameters.
use_router
. use_router (
router ,
force : bool | None = None , # (1)!
)
All of the gateways (routers) has to be run under the master process,
supplying this you can try to bypass this limit.
routers
Dedicated routers, which can be used with register_router().