Expand description
§h2ts-client
A from-scratch HTTP/2 client (RFC 7540 + HPACK/RFC 7541) for Rust WASM
frontends, tunneled over a WebSocket — the Rust sibling of the TypeScript
h2ts client. It deliberately avoids hyper/tokio so it stays tiny in a
wasm32 bundle: a sans-I/O protocol engine plus a pluggable Transport.
HTTP/2 is spoken with prior knowledge (no HTTP/1.1 Upgrade round-trip).
The protocol engine is a module-for-module port of the TypeScript client
(typescript/client/src). Both clients conform to one wire spec
(spec/protocol.md) and the shared conformance suite (conformance/) — that
shared behaviour, not shared code, is what keeps them from diverging.
| module | ports from (TS) | responsibility |
|---|---|---|
frames | frames/ | HTTP/2 frame codec |
hpack | hpack/ | HPACK encoder + decoder |
flow | flow.ts | connection/stream flow control |
connection | connection.ts | multiplexer, request/response flow |
transport | transport/ | the pluggable byte-duplex |
The default web feature provides a browser WebSocket Transport via
web-sys; disable it for host-side engine tests.
Terminate the WebSocket with the Rust server h2ts-server (its h2ts-proxy
binary, or websockify) to reach any HTTP/2 origin.
Re-exports§
pub use connection::connect;pub use connection::ConnectOptions;pub use connection::H2Connection;pub use connection::RequestBody;pub use connection::RequestInit;pub use connection::Response;pub use connection::ResponseBody;pub use errors::ErrorCode;pub use errors::H2Error;pub use hpack::Header;pub use pool::H2Pool;pub use pool::PoolConnection;pub use transport::ByteSink;pub use transport::ByteStream;pub use transport::Transport;pub use transport::TransportError;
Modules§
- connection
- The HTTP/2 connection — port of
connection.ts(+stream.ts,types.ts). - errors
- HTTP/2 error codes (RFC 7540 §7) and the error type used across the crate —
the Rust analogue of
errors.ts. - flow
- HTTP/2 send-side flow-control window (RFC 7540 §6.9) — port of
flow.ts. - frames
- HTTP/2 frame model + codec (RFC 7540 §6) — the Rust port of
frames/types.tsandframes/codec.ts. AFrameis a tagged enum;serialize_framewrites the 9-byte header + payload, andFrameDecoderstreams complete frames out of arbitrary byte chunks, skipping unknown frame types (RFC 7540 §4.1). - hpack
- HPACK (RFC 7541) header compression — port of
hpack/hpack.ts. - pool
- A pool of HTTP/2-over-WebSocket connections — Go-style multi-connection
parallelism (
golang.org/x/net/http2withStrictMaxConcurrentStreams = false). Each request is routed to a connection that still has a free stream slot (per the peer’s SETTINGS_MAX_CONCURRENT_STREAMS); when all are saturated, a new connection is opened. - transport
- The byte-duplex a connection runs over — the Rust analogue of the TS
Transport({ readable, writable }). Anything expressible as a pair of byte streams works: a browserWebSocket(behind thewebfeature), an in-memory channel pair for tests, etc.
Constants§
- DEFAULT_
SUBPROTOCOL - The WebSocket subprotocol an h2ts client offers by default (echoed by the
gateway). Offer it first; see
spec/protocol.md.