HTTP/2

HTTP/2 support via h2 — stream multiplexing, header compression, priority signals

2 min read 356 words

Overview

HTTP/2 support is provided via theh2library. Install the extra:

uv add "bengal-pounce[h2]"

If the extra is missing, the HTTP/2 path fails with an install hint: pip install bengal-pounce[h2].

HTTP/2 provides:

  • Stream multiplexing — Multiple requests over a single TCP connection
  • HPACK header compression — Reduced overhead for repeated headers
  • Priority signals — Clients can indicate request priority
  • Server push — Not implemented (deprecated in most browsers)

Requirements

HTTP/2 requires TLS with ALPN negotiation:

pounce serve --app myapp:app --ssl-certfile cert.pem --ssl-keyfile key.pem

When a client connects with TLS and advertises h2via ALPN, Pounce selects the HTTP/2 handler automatically. Clients that only support HTTP/1.1 continue to work.

Stream Multiplexing

In HTTP/2, multiple requests share a single TCP connection. Each request is a "stream" with its own ID. Pounce creates a separate ASGI scope for each stream, so your application handles each request independently.

flowchart LR Conn["Connection\n(1 TCP socket)"] Conn --> S1["Stream 1\nGET /index.html"] Conn --> S3["Stream 3\nGET /style.css"] Conn --> S5["Stream 5\nGET /script.js"] Conn --> S7["Stream 7\nGET /data.json"]

All streams are processed concurrently within the worker's asyncio event loop.

Built-in endpoints use the same pre-ASGI dispatch as HTTP/1.1: configured health checks, the opt-in/_pounce/infointrospection endpoint, and RFC 9842 compression-dictionary downloads are available over HTTP/2 and report the serving worker's real ID.

Priority Signals

Pounce parses HTTP Priority Signals (RFC 9218) and uses them internally for stream scheduling. Clients can indicate request urgency and whether responses can be delivered incrementally.

ASGI Scope

HTTP/2 requests produce a standard ASGI HTTP scope. Thehttp_version field is "2":

{
    "type": "http",
    "asgi": {"version": "3.0"},
    "http_version": "2",
    "method": "GET",
    "path": "/",
    "headers": [...],
    ...
}

Valid extension-method tokens are preserved. A QUERYrequest, including its body, reaches the app withscope["method"] == "QUERY". Pounce does not add application or cache behavior for the still-draft method; see Extension Methods and QUERY for the support boundary.

See Also

  • HTTP/1.1 — Default protocol
  • WebSocket — HTTP/2 WebSocket support when both extras are installed
  • TLS — Setting up TLS for HTTP/2