Skip to content

Add an asyncio HTTP/2 client example with TLS integration tests - #1336

Open
ac1982 wants to merge 1 commit into
python-hyper:masterfrom
ac1982:docs/asyncio-client-example
Open

ac1982 wants to merge 1 commit into
python-hyper:masterfrom
ac1982:docs/asyncio-client-example

Conversation

@ac1982

@ac1982 ac1982 commented Oct 13, 2026

Copy link
Copy Markdown

The asyncio examples currently show servers, while the client examples use blocking sockets or Twisted. This adds a runnable single-request asyncio client and a documentation page linked from the client examples, addressing #1239.

The example uses verified TLS and checks ALPN before sending HTTP/2 bytes. One coroutine owns the h2 connection, flushes generated frames with drain(), and acknowledges received flow-controlled data. It handles headers, body and trailers, distinguishes completion from premature EOF/reset/GOAWAY, and closes the transport on errors or cancellation. Server push is disabled and only the requested stream is collected. The documentation explains the in-memory body and single-request scope.

Nine integration cases exercise a local TLS server, including padded 256 KiB responses spanning the flow-control window, trailers, empty responses, GOAWAY with/without completion, reset, EOF, timeout cleanup, and failed ALPN. Test certificates are generated in temporary directories with OpenSSL; those cases explicitly skip if OpenSSL is unavailable.

Validation on Linux ARM64:

  • Python 3.12: 1,671 tests pass, retaining 100% h2 branch coverage (baseline: 1,662 tests, 100%).
  • Python 3.10: all nine example cases pass.
  • Actual CLI subprocess receives the binary body and trailers over local verified TLS; untrusted certificates and hostname mismatch are rejected.
  • Ruff source checks, strict-bytes mypy, strict Sphinx HTML build, manifest, sdist/wheel build and Twine checks pass.

No core protocol code changes. Other platforms, the remaining Python matrix and h2spec were not run locally.

AI assistance was used for implementation and validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant