Skip to content

blackbull.client.http2

blackbull.client.http2

HTTP/2 client (RFC 7540).

HTTP2Client opens a single TCP/TLS connection, sends the connection preface and an initial SETTINGS frame, then drives request/response exchanges over multiple concurrent streams.

The client is intended for wire-level testing of BlackBull's ASGIServer rather than as a feature-rich application client.

ClientResponse dataclass

A complete HTTP response received by the client.

status is the HTTP status code (parsed from the :status pseudo-header). headers are the regular response headers as a Headers instance (bytes-keyed, lowercase-indexed). body is the concatenation of all DATA-frame payloads received on the stream.

HTTP2Client

Async HTTP/2 client.

Use as an async context manager::

async with HTTP2Client('localhost', 8000) as c:
    res = await c.request(HTTPMethod.GET, '/')

ssl=None (the default) selects plaintext h2c. Provide an ssl.SSLContext with set_alpn_protocols(['h2']) for h2 over TLS.

Multiple request() calls share the same connection: each gets its own odd, monotonically-increasing client-initiated stream ID (RFC 7540 ยง5.1.1) and the responses are demultiplexed by the receive loop.

receive_raw_frame() async

Escape hatch: read one raw frame; bypasses the receive loop.

Only safe to call when the receive loop is not running (i.e. before __aenter__ finishes or after the loop has been cancelled).

request(method, path, *, headers=(), body=b'') async

Send one request and await the matching response.

Adds :authority automatically from host:port. Header names and values may be str or bytes; they are normalised to ASCII str for HPACK encoding.

send_raw_frame(frame) async

Escape hatch: write a raw frame to the wire (negative-path tests).