Skip to main content

ringline_http/
lib.rs

1//! Async HTTP client for the ringline io_uring runtime.
2//!
3//! Provides HTTP/2 and HTTP/1.1 client connections built on top of the sans-IO
4//! `ringline-h2` framing layer and the ringline async runtime. The crate
5//! bridges the gap between the sans-IO state machines and the `ConnCtx` I/O
6//! primitives.
7//!
8//! # Architecture
9//!
10//! `H2AsyncConn` wraps an `H2Connection` (sans-IO) with a pump loop that
11//! continuously transfers bytes between `ConnCtx` and the H2 state machine.
12//! This uses a fire/recv pipelining pattern: fire requests
13//! synchronously, then pump until responses arrive.
14//!
15//! `H1Conn` provides simple HTTP/1.1 request-response over a `ConnCtx`,
16//! with header parsing and chunked transfer decoding.
17//!
18//! `HttpClient` is the top-level API wrapping either protocol with a
19//! reqwest-style builder interface.
20//!
21//! # Example
22//!
23//! ```rust,ignore
24//! use ringline_http::HttpClient;
25//!
26//! async fn example() -> Result<(), ringline_http::HttpError> {
27//!     let mut client = HttpClient::connect_h2(addr, "example.com").await?;
28//!
29//!     let resp = client.get("/api/data")
30//!         .header("authorization", "Bearer tok")
31//!         .send()
32//!         .await?;
33//!
34//!     assert_eq!(resp.status(), 200);
35//!     let body = resp.bytes();
36//!     Ok(())
37//! }
38//! ```
39//!
40//! # Multiplexed API
41//!
42//! ```rust,ignore
43//! use ringline_http::H2AsyncConn;
44//!
45//! async fn example() -> Result<(), ringline_http::HttpError> {
46//!     let mut h2 = H2AsyncConn::connect(addr, "example.com").await?;
47//!
48//!     let s1 = h2.fire_request("GET", "/a", "example.com", &[], None)?;
49//!     let s2 = h2.fire_request("GET", "/b", "example.com", &[], None)?;
50//!
51//!     let (stream_id, resp) = h2.recv().await?;
52//!     let (stream_id, resp) = h2.recv().await?;
53//!     Ok(())
54//! }
55//! ```
56//!
57//! # Copy Semantics
58//!
59//! | Path | Copies | Notes |
60//! |------|--------|-------|
61//! | **H2 recv headers** | 1 | `with_data` feeds `h2.recv()` which copies into `recv_buf`. Headers decoded from owned `Vec<u8>`. |
62//! | **H2 recv body** | 1 | `h2.recv()` copies into `recv_buf`. `H2Event::Data` contains `Vec<u8>`. |
63//! | **H2 send** | 2 | Headers encoded into `h2.send_buf`, then `send_nowait()` copies to pool. |
64//! | **H1 recv** | 1 | `with_data` provides borrowed slice, headers parsed in-place, body copied out. |
65//! | **H1 send** | 1 | Serialize to `Vec<u8>`, `send_nowait()` copies to pool. |
66
67pub mod body;
68pub mod client;
69pub(crate) mod compress;
70pub mod error;
71pub mod h1_conn;
72pub mod h2_conn;
73pub mod pool;
74pub mod request;
75pub mod response;
76pub mod streaming;
77
78pub use client::HttpClient;
79pub use error::HttpError;
80pub use h1_conn::{H1Conn, H1StreamingResponse};
81pub use h2_conn::{H2AsyncConn, H2StreamingResponse};
82pub use pool::{Pool, PoolConfig, PooledClient, Protocol};
83pub use request::RequestBuilder;
84pub use response::Response;
85pub use streaming::StreamingResponse;