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 oneH2StreamBridgeper stream, which builds the scope and creates receive/send callables. The send callable serializes via the sharedH2Connection(which is single-threaded within the worker's event loop — no lock needed).

Functions

build_h2_scope 4 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]) -> dict[str, Any]

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

Same asbuild_scope() for H1, but sets http_version: "2" andscheme: "https"(HTTP/2 typically requires TLS).

Parameters
Name Type Description
request RequestReceived
config ServerConfig
client tuple[str, int]
server tuple[str, int]
Returns
dict[str, Any]
create_h2_receive 1 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]]) -> 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]]
Returns
Receive
create_h2_send 8 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, request_method: bytes = b'GET', request_id: str | None = None) -> Send

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

Serializes via the shared H2Connection. After each h2 operation, flushesdata_to_send()to the writer.

Parameters
Name Type Description
h2_conn 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

Mutable holder populated with response status and byte count.

timing ServerTiming | None

Optional Server-Timing builder.

Default:None
compressor Compressor | None

Optional compressor for response body.

Default:None
request_method bytes Default:b'GET'
request_id str | None Default:None
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
writer asyncio.StreamWriter