Skip to content

Routing

Classes

RouteRule

RouteRule(action, subject=None, stage: str = stages.REQUEST)

Represents a routing rule.


actions

.actions()

Actions available for routing rules.

Values returned by actions:

1
2
3
4
* ``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

.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
.ERROR = 'error'

Applied as soon as an HTTP status code is generate. Recursive chain.


FINAL
.FINAL = 'final'

Applied after the response has been sent to the client.


REQUEST
.REQUEST = ''

Applied before the request is passed to the plugin.


RESPONSE
.RESPONSE = 'response'

Applied after the last response header has been generated (just before sending the body).


subjects

.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.


transforms

.transforms()

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

.var_functions()

Functions that can be applied to variables.


vars

.vars()

Routing variables.


Routing

Routing(*args, **kwargs)

OptionsGroup

Routing subsystem.

You can use the internal routing subsystem to dynamically alter the way requests are handled.

Note

Since 1.9


name

.name: str = ''

Name to represent the group.


plugin

.plugin: bool | str = False

Indication this option group belongs to a plugin.


header_add

.header_add(name: str, value: str)

Automatically add HTTP headers to response.


header_collect

1
2
3
4
5
.header_collect(
    name: str, 
    target_var: str, 
    pull: bool = False,  # (1)!
)
  1. Whether to remove header from response.

Store the specified response header in a request var (optionally removing it from the response).


header_remove

.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

1
2
3
4
.set_error_page(
    status: int,  # (1)!
    html_fpath: str,  # (2)!
)
  1. HTTP status code.

  2. HTML page file path.

Add an error page (html) for managed 403, 404, 500 response.


set_error_pages

1
2
3
4
.set_error_pages(
    codes_map: dict | None = None,  # (1)!
    common_prefix: Strpath = None,  # (2)!
)
  1. 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.

  2. Common path (prefix) for all files.

Add an error pages for managed 403, 404, 500 responses.

Shortcut for .set_error_page().


set_geoip_params

1
2
3
4
.set_geoip_params(
    db_country: str | None = None, 
    db_city: str | None = None
)

Sets GeoIP parameters.


use_router

1
2
3
4
.use_router(
    router, 
    force: bool | None = None,  # (1)!
)
  1. All of the gateways (routers) has to be run under the master process, supplying this you can try to bypass this limit.

modifiers


routers

.routers()

Dedicated routers, which can be used with register_router().