http
The shared Rust crate defining Request, Response, and other core HTTP types
Repository Health
Technical Analysis
http is a foundational Rust crate providing the shared Request, Response, Method, StatusCode, Uri, Version, and HeaderMap types that most of the Rust HTTP ecosystem — hyper, tonic, axum, reqwest, tower, and many others — builds on top of. Rather than each HTTP-adjacent crate defining its own incompatible request/response representations, they all depend on http so values can move between a client, a server, and any middleware in between without conversion glue.
The crate intentionally contains no networking, parsing, or I/O code of its own; it exists purely to standardize the vocabulary types that HTTP-related crates pass to each other, with an optimized HeaderMap implementation as its most substantial piece of internal logic.
What You Get
Request<T>andResponse<T>generic types with ergonomic builder APIs for constructing HTTP messagesHeaderMap- a purpose-built multi-map optimized for HTTP header storage and case-insensitive lookupMethod,StatusCode,Uri, andVersiontypes shared across the entire Rust HTTP ecosystem- Zero-copy-friendly
HeaderName/HeaderValuetypes backed bybytes::Bytes - Conversion trait implementations (
convert.rs) so common std types interoperate cleanly with the crate’s types
Common Use Cases
- Defining the request/response types passed between a client and server built on hyper, tonic, or axum
- Writing HTTP middleware (a
tower::Layer) that needs to inspect or modify headers, method, or status without depending on any particular server implementation - Implementing a new HTTP client or server that wants to interoperate with the existing hyper-ecosystem tooling out of the box
- Building an HTTP proxy or gateway that manipulates requests/responses using a common, well-tested type vocabulary
Under The Hood
Architecture Across roughly 14,500 lines, the crate is organized around independent, focused modules — request.rs and response.rs define the generic Request<T>/Response<T> builder types, header/ implements the HeaderMap/HeaderName/HeaderValue trio as its own self-contained sub-module, and method.rs, status.rs, version.rs, uri/ each own one small, well-scoped vocabulary type — reflecting the crate’s deliberate scope discipline of shipping types and nothing else. Tech Stack Depends on bytes for zero-copy byte storage in header values and little else, keeping the dependency graph shallow since this crate sits at the base of the dependency tree for a large share of the Rust HTTP ecosystem (hyper, axum, tonic, reqwest, tower). Code Quality tests/header_map.rs and tests/header_map_fuzz.rs reflect that HeaderMap — the crate’s most algorithmically complex piece, since it’s a custom hash-map variant tuned for HTTP header access patterns — receives targeted fuzz testing in addition to conventional unit tests, appropriate rigor for a type this deeply relied upon. API Design The builder pattern on Request/Response (Request::builder().method(...).uri(...).body(...)) is now the de facto idiom across the Rust HTTP ecosystem precisely because this crate established it first, and extensive From/TryFrom conversions in convert.rs mean callers rarely need explicit type-conversion boilerplate at API boundaries.