Module

middleware.allowed_hosts

Allowed hosts middleware — reject requests with unrecognized Host header.

Validates the Host header against a whitelist. Wildcard".example.com" matches subdomains."*"allows all hosts (dev default).

Classes

AllowedHostsMiddleware 2
Reject requests whose Host header does not match allowed_hosts. Usage:: from chirp.middleware…

Reject requests whose Host header does not match allowed_hosts.

Usage::

from chirp.middleware.allowed_hosts import AllowedHostsMiddleware

app.add_middleware(AllowedHostsMiddleware(("example.com", ".example.com")))

Methods

Internal Methods 2
__init__ 2
def __init__(self, allowed_hosts: tuple[str, ...] = ('*',), *, debug: bool = False) -> None
Parameters
Name Type Description
allowed_hosts Default:('*',)
debug Default:False
__call__ 2 AnyResponse
async
async def __call__(self, request: Request, next: Next) -> AnyResponse
Parameters
Name Type Description
request
next
Returns
AnyResponse