Pyjoyment.Plugin.HeaderCondition - Header condition plugin¶
# Pyjoyment
app.plugin('HeaderCondition')
app.routes.get('/foo').requires(headers={'Referer': re.compile(r'example\.com')})
# Pyjoyment.Lite
plugin('HeaderCondition')
@get('/').requires(headers={'Referer': re.compile(r'example\.com')})
def index(c): ...
# All headers need to match
app.routes.get('/foo').requires(headers={'X-Secret-Header': 'Foo', 'Referer': re.compile(r'example\.com')})
# The "agent" condition is a shortcut for the "User-Agent" header
@get('/').requires(agent=re.compile(r'Firefox'))
def firefox(c): ...
# The "host" condition is a shortcut for the detected host
@get('/').requires(host=re.compile(r'mojolicious\.org'))
def mojolicious(c): ...
Pyjoyment.Plugin.HeaderCondition is a route condition for header-based
routes.
This is a core plugin, that means it is always enabled and its code a good example for learning to build new plugins, you’re welcome to fork it.
See Pyjoyment.Plugins for a list of plugins that are available by
default.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojolicious::Plugin::HeaderCondition of Mojolicious 9.49.
- class Pyjoyment.Plugin.HeaderCondition.Pyjoyment_Plugin_HeaderCondition¶
Pyjoyment.Plugin.HeaderConditioninherits all methods fromPyjoyment.Pluginand implements the following new ones.- register(app: Pyjoyment_App, conf: dict[str, Any] | None = None) None¶
plugin.register(Pyjoyment.new())
Register conditions in
Pyjoymentapplication.