# _request_pipeline

URL: /pounce/api/_request_pipeline/
Section: api
Description: 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).

---

> For a complete page index, fetch /pounce/llms.txt.

Open LLM text
(/pounce/api/_request_pipeline/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_pipeline%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_pipeline%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_pipeline%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_request_pipeline%2Findex.txt)

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

1Class6Functions

## Classes

`BuiltinResponse`

4

▼

A protocol-neutral response produced by a built-in endpoint.

A protocol-neutral response produced by a built-in endpoint.

#### Attributes

Name
Type
Description

`kind`

`Literal['health', 'introspection', 'dictionary']`

—

`status`

`int`

—

`headers`

`list[tuple[bytes, bytes]]`

—

`body`

`bytes`

—

## 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 (/pounce/api/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 (/pounce/api/protocols/_base/#RequestReceived)`

`config`
`ServerConfig (/pounce/api/config/#ServerConfig)`

`client`
`tuple[str, int]`

`server`
`tuple[str, int]`

`lifespan_state`
`dict[str, Any]`

##### Returns

`tuple[dict[str, Any], str | None]`

`maybe_build_builtin_response`

6

`BuiltinResponse (/pounce/api/_request_pipeline/#BuiltinResponse) | None`

▼

Select and build a built-in endpoint response before ASGI dispatch.

Endpoint s…

`def maybe_build_builtin_response(config: ServerConfig, method: str | bytes, path: str, *, worker_id: int, active_connections: _IntProvider, draining: _BoolProvider = False) -> BuiltinResponse | None`

Select and build a built-in endpoint response before ASGI dispatch.

Endpoint selection is shared across every HTTP transport while response
serialization remains protocol-owned. Providers are evaluated lazily so
normal application requests do not acquire connection-count locks or call
drain-state hooks on the latency-sensitive request path.

##### Parameters

Name
Type
Description

`config`
`ServerConfig (/pounce/api/config/#ServerConfig)`

`method`
`str | bytes`

`path`
`str`

`worker_id`
`int`

`active_connections`
`_IntProvider`

`draining`
`_BoolProvider`

Default:`False`

##### Returns

`BuiltinResponse (/pounce/api/_request_pipeline/#BuiltinResponse) | None`

`negotiate_compressor`

3

`tuple[Compressor (/pounce/api/_compression/#Compressor) | None,…`

▼

Negotiate content-encoding compression from request headers.

Returns (compress…

`def negotiate_compressor(config: ServerConfig, headers: Sequence[tuple[bytes, bytes]], *, request_target: str = '') -> tuple[Compressor | None, CompressionDictionary | None]`

Negotiate content-encoding compression from request headers.

Returns (compressor, dictionary) — dictionary is non-None only when
`dcz`(dictionary-compressed zstd) encoding is selected.

##### Parameters

Name
Type
Description

`config`
`ServerConfig (/pounce/api/config/#ServerConfig)`

`headers`
`Sequence[tuple[bytes, bytes]]`

`request_target`
`str`

Default:`''`

##### Returns

`tuple[Compressor (/pounce/api/_compression/#Compressor) | None, CompressionDictionary (/pounce/api/_compression/#CompressionDictionary) | None]`

`negotiate_compressor_from_meta`

4

`tuple[Compressor (/pounce/api/_compression/#Compressor) | None,…`

▼

Negotiate compression from already-extracted header values.

Meta-keyed entry p…

`def negotiate_compressor_from_meta(config: ServerConfig, accept_encoding: bytes | None, available_dictionary: bytes | None, *, request_target: str = '') -> tuple[Compressor | None, CompressionDictionary | None]`

Negotiate compression from already-extracted header values.

Meta-keyed entry point for the sync-worker hot path: the caller passes the
`accept-encoding` and `available-dictionary`values already pulled out
of `_RequestMeta` (/pounce/api/sync_worker/#_RequestMeta) (no redundant header scan) plus the decoded request
target. Behaviour is identical to `negotiate_compressor` (/pounce/api/_request_pipeline/#negotiate_compressor)().

Returns (compressor, dictionary) — dictionary is non-None only when
`dcz`(dictionary-compressed zstd) encoding is selected.

##### Parameters

Name
Type
Description

`config`
`ServerConfig (/pounce/api/config/#ServerConfig)`

`accept_encoding`
`bytes | None`

`available_dictionary`
`bytes | None`

`request_target`
`str`

Default:`''`

##### Returns

`tuple[Compressor (/pounce/api/_compression/#Compressor) | None, CompressionDictionary (/pounce/api/_compression/#CompressionDictionary) | 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 (/pounce/api/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`
