h2ts_client/lib.rs
1//! # h2ts-client
2//!
3//! A from-scratch HTTP/2 client (RFC 7540 + HPACK/RFC 7541) for **Rust WASM
4//! frontends**, tunneled over a WebSocket — the Rust sibling of the TypeScript
5//! [`h2ts`] client. It deliberately avoids `hyper`/`tokio` so it stays tiny in a
6//! `wasm32` bundle: a **sans-I/O protocol engine** plus a pluggable [`Transport`].
7//! HTTP/2 is spoken with prior knowledge (no HTTP/1.1 `Upgrade` round-trip).
8//!
9//! The protocol engine is a module-for-module port of the TypeScript client
10//! (`typescript/client/src`). Both clients conform to one wire spec
11//! (`spec/protocol.md`) and the shared conformance suite (`conformance/`) — that
12//! shared *behaviour*, not shared code, is what keeps them from diverging.
13//!
14//! | module | ports from (TS) | responsibility |
15//! |-----------------|---------------------|----------------------------------------|
16//! | [`frames`] | `frames/` | HTTP/2 frame codec |
17//! | [`hpack`] | `hpack/` | HPACK encoder + decoder |
18//! | [`flow`] | `flow.ts` | connection/stream flow control |
19//! | [`connection`] | `connection.ts` | multiplexer, request/response flow |
20//! | [`transport`] | `transport/` | the pluggable byte-duplex |
21//!
22//! The default `web` feature provides a browser `WebSocket` [`Transport`] via
23//! `web-sys`; disable it for host-side engine tests.
24//!
25//! Terminate the WebSocket with the Rust server [`h2ts-server`] (its `h2ts-proxy`
26//! binary, or `websockify`) to reach any HTTP/2 origin.
27//!
28//! [`h2ts`]: https://www.npmjs.com/package/@debdattabasu/h2ts
29//! [`h2ts-server`]: https://crates.io/crates/h2ts-server
30
31mod bytes;
32pub mod connection;
33pub mod errors;
34pub mod flow;
35pub mod frames;
36pub mod hpack;
37pub mod pool;
38pub mod transport;
39
40/// The WebSocket subprotocol an h2ts client offers by default (echoed by the
41/// gateway). Offer it first; see `spec/protocol.md`.
42pub const DEFAULT_SUBPROTOCOL: &str = "h2ts";
43
44pub use connection::{
45 connect, ConnectOptions, H2Connection, RequestBody, RequestInit, Response, ResponseBody,
46};
47pub use errors::{ErrorCode, H2Error};
48pub use hpack::Header;
49pub use pool::{H2Pool, PoolConnection};
50pub use transport::{ByteSink, ByteStream, Transport, TransportError};
51
52// Browser WebSocket transport — wasm32 only, behind the default `web` feature.
53#[cfg(all(feature = "web", target_arch = "wasm32"))]
54mod web;
55#[cfg(all(feature = "web", target_arch = "wasm32"))]
56pub use web::{connect_pool, connect_websocket, websocket_transport};