Skip to main content

io_http/
lib.rs

1#![no_std]
2#![deny(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4
5//! # io-http
6//!
7//! I/O-free HTTP client coroutines. Every network exchange is a
8//! resumable state machine that emits read and write requests instead
9//! of performing I/O itself: the caller owns the socket and pumps the
10//! coroutine with the bytes it read, whatever the runtime (blocking,
11//! async, in-memory tests). The `client` feature ships a ready-made
12//! std-blocking pump for callers who just want a working client.
13//!
14//! ## Layout: one folder per RFC
15//!
16//! io-http covers HTTP in general; today HTTP/1.0 and HTTP/1.1 are
17//! implemented. The source tree mirrors how the HTTP specification
18//! itself is split, one module per RFC, so the RFC number is the
19//! version discriminator: a future version (HTTP/2, HTTP/3) would slot
20//! in as its own RFC modules alongside the existing ones.
21//! [`rfc9110`] holds the version-agnostic semantics shared by every
22//! wire format: the request and response types, status codes, header
23//! name constants, authentication challenge parsing, and the output
24//! and yield types common to both send coroutines. [`rfc1945`]
25//! implements the HTTP/1.0 wire protocol and [`rfc9112`] the HTTP/1.1
26//! one: each ships its request serialiser and send coroutine, and
27//! HTTP/1.1 adds the response-head parser plus two chunked
28//! transfer-coding decoders (whole-body and streaming).
29//!
30//! Around the wire protocols, [`rfc6750`] and [`rfc7617`] provide the
31//! bearer and basic authorization header helpers, with secrets
32//! redacted from debug output; [`rfc8615`] wraps the HTTP/1.1 send
33//! coroutine into a well-known URI discovery coroutine surfacing the
34//! redirect target.
35//!
36//! Two modules span the RFC modules and therefore live at the crate
37//! root: [`coroutine`] defines the coroutine contract every state
38//! machine implements, and [`sse`] parses W3C Server-Sent Events
39//! frames (a WHATWG HTML Living Standard, not an RFC, hence its own
40//! name). The optional [`client`] module (`client` feature) is the
41//! std-blocking pump: a light client wrapping any stream you opened
42//! yourself, or a full client opening the TCP/TLS connection itself
43//! when one of the TLS features is enabled.
44//!
45//! ## The coroutine contract
46//!
47//! Every coroutine implements [`coroutine::HttpCoroutine`]: a resume
48//! method taking the bytes read since the last step and returning
49//! either an intermediate yield or a terminal completion. Standard
50//! coroutines yield the shared read/write requests of
51//! [`coroutine::HttpYield`]; richer coroutines declare their own yield
52//! type, like the send coroutines surfacing 3xx redirects to the
53//! caller instead of following them, or the streaming decoders
54//! yielding one frame at a time. Completion carries a per-coroutine
55//! output or error; the [`http_try`] macro chains an inner coroutine
56//! step inside an outer resume, re-yielding and short-circuiting like
57//! the question mark operator.
58//!
59//! ## Conventions
60//!
61//! The crate is no_std with alloc; std only enters behind the `client`
62//! feature. Public items carry the version-agnostic `Http` prefix when
63//! they belong to the shared semantics, and the version-scoped
64//! `Http10` / `Http11` prefix when they are tied to a wire format; the
65//! `Sse` family keeps its own deliberate namespace. Logging follows
66//! the library rules: state changes at debug level, in-process steps
67//! and data dumps at trace level.
68
69extern crate alloc;
70#[cfg(feature = "client")]
71extern crate std;
72
73#[cfg(feature = "client")]
74pub mod client;
75pub mod coroutine;
76pub mod rfc1945;
77pub mod rfc6750;
78pub mod rfc7617;
79pub mod rfc8615;
80pub mod rfc9110;
81pub mod rfc9112;
82pub mod sse;