headers
Strongly-typed HTTP header definitions for Rust, extracted from and used by the hyper HTTP stack.
Repository Health
Technical Analysis
headers is a Rust crate providing strongly-typed representations of common HTTP headers, originally built for and used by hyper. Instead of manipulating raw header strings, you work with typed structs such as ContentType, Authorization, and Range that parse, validate, and encode themselves correctly. A HeaderMapExt trait adds typed get and insert methods to the standard http::HeaderMap, and a derive macro helps define custom typed headers.
What You Get
- Typed structs for many standard HTTP headers with correct parsing and encoding
- A HeaderMapExt trait adding typed access to http::HeaderMap
- A derive macro (headers-derive) for defining custom typed headers
- A stable core (headers-core) shared across the hyper ecosystem
Common Use Cases
- Reading and writing HTTP headers safely in hyper- or http-based servers and clients
- Defining custom application headers with correct parsing behavior
- Avoiding string-typing bugs when handling Authorization, Content-Type, or Range headers
Under The Hood
Architecture
The design centers on a Header trait defining how a type decodes from and encodes to raw HeaderValues. Concrete header structs implement it, and the HeaderMapExt trait layers typed accessors over http::HeaderMap by looking up the header’s canonical name and running its decode logic. The workspace splits the trait and primitives into headers-core, the header library into headers, and the custom-header derive into headers-derive.
Tech Stack
A Rust workspace crate built on the http crate’s HeaderMap and HeaderValue types, with bytes and base64 helpers for value encoding. Published on crates.io as headers, licensed MIT and maintained under the hyperium organization.
Code Quality
Backed by the hyper project, the crate has broad real-world exercise (over 138M downloads) and per-header unit tests. Development activity is lower now that the API is stable, but the code is mature and widely depended upon across the Rust HTTP ecosystem.
API Design
The typed-get and typed-insert API is ergonomic and hard to misuse, and the derive macro keeps custom headers low-effort. Developers already using the http crate adopt it with almost no new concepts; the main learning is which typed headers exist and how their values map.