Module

_request_pipeline

Shared request pipeline — functions used by both Worker and SyncWorker.

Eliminates duplication across the two worker types and ensures feature parity (access log filter, duration tracking, request ID propagation).

Functions

is_trusted_peer 2 bool
Check if the client address is in the trusted hosts set.
def is_trusted_peer(config: ServerConfig, client_addr: str) -> bool
Parameters
Name Type Description
config ServerConfig
client_addr str
Returns
bool
prepare_request 5 tuple[dict[str, Any], st…
Build ASGI scope, extract request ID, and set extensions. Returns (scope, requ…
def prepare_request(request: RequestReceived, config: ServerConfig, client: tuple[str, int], server: tuple[str, int], lifespan_state: dict[str, Any]) -> tuple[dict[str, Any], str | None]

Build ASGI scope, extract request ID, and set extensions.

Returns (scope, request_id).

Parameters
Name Type Description
request RequestReceived
config ServerConfig
client tuple[str, int]
server tuple[str, int]
lifespan_state dict[str, Any]
Returns
tuple[dict[str, Any], str | None]
negotiate_compressor 2 Compressor | None
Negotiate content-encoding compression from request headers.
def negotiate_compressor(config: ServerConfig, headers: Sequence[tuple[bytes, bytes]]) -> Compressor | None
Parameters
Name Type Description
config ServerConfig
headers Sequence[tuple[bytes, bytes]]
Returns
Compressor | None
log_request 10 None
Log an access log entry, respecting the access_log_filter.
def log_request(config: ServerConfig, method: str, target: str, status: int, bytes_sent: int, duration_ms: float, client_str: str, *, http_version: str = '1.1', request_id: str | None = None, worker_id: int | None = None) -> None
Parameters
Name Type Description
config ServerConfig
method str
target str
status int
bytes_sent int
duration_ms float
client_str str
http_version str Default:'1.1'
request_id str | None Default:None
worker_id int | None Default:None