# h2_bridge

URL: /pounce/api/asgi/h2_bridge/
Section: asgi
Description: HTTP/2 ASGI bridge — maps H2Connection streams to ASGI scope/receive/send.

Each HTTP/2 stream maps to one ASGI invocation, just like one HTTP/1.1
request maps to one ASGI invocation. The difference is that multiple
streams can run concurrently on the same TCP connection.

The worker creates one ``H2StreamBridge`` per stream, which builds the
scope and creates receive/send callables. The send callable serializes
via the shared ``H2Connection`` (which is single-threaded within the
worker's event loop — no lock needed).

---

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

Open LLM text
(/pounce/api/asgi/h2_bridge/index.txt)

Share with AI

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

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

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

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

Module

#
`asgi.h2_bridge`

HTTP/2 ASGI bridge — maps H2Connection streams to ASGI scope/receive/send.

Each HTTP/2 stream maps to one ASGI invocation, just like one HTTP/1.1
request maps to one ASGI invocation. The difference is that multiple
streams can run concurrently on the same TCP connection.

The worker creates one`H2StreamBridge`per stream, which builds the
scope and creates receive/send callables. The send callable serializes
via the shared`H2Connection`(which is single-threaded within the
worker's event loop — no lock needed).

4Functions

## Functions

`build_h2_scope`

5

`dict[str, Any]`

▼

Build an ASGI HTTP scope from an HTTP/2 request.

Same as ``build_scope()`` for…

`def build_h2_scope(request: RequestReceived, config: ServerConfig, client: tuple[str, int], server: tuple[str, int], *, state: dict[str, Any] | None = None) -> dict[str, Any]`

Build an ASGI HTTP scope from an HTTP/2 request.

Same as `build_scope()` (/pounce/api/asgi/bridge/#build_scope) for H1, but sets `http_version: "2"`
and`scheme: "https"`(HTTP/2 typically requires TLS).

##### 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]`

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

Default:`None`

##### Returns

`dict[str, Any]`

`create_h2_receive`

2

`Receive`

▼

Create an ASGI receive callable for an HTTP/2 stream.

The worker pushes body e…

`def create_h2_receive(body_queue: asyncio.Queue[dict[str, Any]], *, timeout: float | None = None) -> Receive`

Create an ASGI receive callable for an HTTP/2 stream.

The worker pushes body events into the queue as DATA frames arrive.

##### Parameters

Name
Type
Description

`body_queue`
`asyncio.Queue[dict[str, Any]]`

`timeout`
`float | None`

Default:`None`

##### Returns

`Receive`

`create_h2_send`

14

`Send`

▼

Create an ASGI send callable for an HTTP/2 stream.

Serializes via the shared H…

`def create_h2_send(h2_conn: H2Connection, stream_id: int, writer: asyncio.StreamWriter, state: SendState, *, timing: ServerTiming | None = None, compressor: Compressor | None = None, dictionary_hash: str | None = None, request_method: bytes = b'GET', request_id: str | None = None, config: ServerConfig | None = None, server: tuple[str, int] | None = None, scheduler: PriorityScheduler | None = None, flow_control_updated: asyncio.Event | None = None, compression_min_size: int = 0) -> Send`

Create an ASGI send callable for an HTTP/2 stream.

Serializes via the shared H2Connection. After each h2 operation,
flushes `data_to_send()` (/pounce/api/protocols/h2/#H2Connection) to the writer.

##### Parameters

Name
Type
Description

`h2_conn`
`H2Connection (/pounce/api/protocols/h2/#H2Connection)`

The H2Connection managing this connection.

`stream_id`
`int`

The h2 stream identifier for this request.

`writer`
`asyncio.StreamWriter`

The asyncio StreamWriter for the TCP connection.

`state`
`SendState (/pounce/api/asgi/bridge/#SendState)`

Mutable holder populated with response status and byte count.

`timing`
`ServerTiming (/pounce/api/_timing/#ServerTiming) | None`

Optional Server-Timing builder.

Default:`None`

`compressor`
`Compressor (/pounce/api/_compression/#Compressor) | None`

Optional compressor for response body.

Default:`None`

`dictionary_hash`
`str | None`

Default:`None`

`request_method`
`bytes`

Default:`b'GET'`

`request_id`
`str | None`

Default:`None`

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

Default:`None`

`server`
`tuple[str, int] | None`

Default:`None`

`scheduler`
`PriorityScheduler (/pounce/api/_priority/#PriorityScheduler) | None`

Default:`None`

`flow_control_updated`
`asyncio.Event | None`

Default:`None`

`compression_min_size`
`int`

Default:`0`

##### Returns

`Send`

`_flush`

2

`None`

▼

Write pending h2 output bytes to the transport.

`def _flush(h2_conn: H2Connection, writer: asyncio.StreamWriter) -> None`

##### Parameters

Name
Type
Description

`h2_conn`
`H2Connection (/pounce/api/protocols/h2/#H2Connection)`

`writer`
`asyncio.StreamWriter`
