httpdate
A tiny, zero-dependency Rust crate for parsing and formatting the timestamps found in HTTP header fields.
Repository Health
Technical Analysis
httpdate provides the two functions almost every Rust HTTP stack eventually needs: parse_http_date and fmt_http_date, converting between std::time::SystemTime and the timestamp formats used in headers like Date, Last-Modified, and If-Modified-Since. It supports the preferred IMF-fixdate format as well as the legacy RFC 850 and ANSI C asctime formats for parsing, and always formats using IMF-fixdate on output, matching the HTTP specification’s recommendations.
The crate exposes an HttpDate type that packs a timestamp into 8 bytes (versus 16 for SystemTime), with Display/FromStr implementations that avoid intermediate allocation. It has zero runtime dependencies, forbids unsafe code, and is widely used as a transitive dependency across the Rust HTTP ecosystem.
What You Get
parse_http_date(&str) -> Result<SystemTime, Error>accepting IMF-fixdate, RFC 850, and ascdate formats with two-digit years mapped to 1970-2069fmt_http_date(SystemTime) -> Stringproducing spec-compliant IMF-fixdate output for response headers- An
HttpDatetype implementingDisplay/FromStrand conversions to/fromSystemTime, at half the memory footprint - Zero runtime dependencies and
#![forbid(unsafe_code)], keeping the crate auditable and lightweight to embed - Fuzz-testing setup (
cargo-fuzz) and criterion benchmarks included in the repo
Common Use Cases
- Formatting
DateandLast-Modifiedresponse headers in a Rust HTTP server - Parsing
If-Modified-Since/If-Unmodified-Sincerequest headers for conditional-GET caching logic - Any Rust HTTP client or server crate (e.g. hyper-adjacent stacks) that needs spec-correct HTTP timestamp handling without pulling in a full datetime library
- Cookie expiration timestamp formatting, since cookie
Expiresattributes use the same IMF-fixdate format
Under The Hood
Architecture: The crate is deliberately minimal — src/lib.rs (160 lines) exposes two free functions and re-exports the HttpDate type defined in src/date.rs (420 lines), which implements the actual calendar math, parsing state machine, and Display formatting. HttpDate stores a timestamp in a compact 8-byte representation and converts to/from std::time::SystemTime via TryFrom/Into, so the crate never allocates during formatting except for the final String returned by fmt_http_date. Parsing dispatches across three date grammars (IMF-fixdate, obsolete RFC 850, and ANSI C asctime) using straightforward byte-slice matching rather than a general-purpose parser combinator, keeping the dependency-free footprint intact.
Tech Stack: Pure Rust, edition 2021, MSRV 1.56, with #![forbid(unsafe_code)] and zero runtime dependencies — the only dependency declared anywhere is criterion for dev-time benchmarking. A cargo fuzz harness (fuzz_target_1) is set up for parser robustness testing, and CI runs via GitHub Actions.
Code Quality: Test coverage lives inline alongside the parsing/formatting logic in date.rs, exercising round-trips between SystemTime and each supported date grammar, plus edge cases like two-digit year mapping. The error type is a single opaque Error(()) with a fixed message, a pragmatic choice for a crate with exactly one failure mode (unparseable date string) rather than a proliferation of error variants. Code is small enough (580 lines total) to review end-to-end in minutes, and the forbid(unsafe_code) attribute backs up that simplicity with a compiler-enforced guarantee.
API Design: Two top-level functions cover the 95% use case with no configuration or builder pattern required, and the HttpDate type is available for callers who want to hold a parsed timestamp without immediately converting back to SystemTime. Rustdoc on both public functions states supported formats and the two-digit-year mapping rule directly, so there’s little need to read source to use the crate correctly. The tradeoff is that the API doesn’t expose which of the three date grammars matched, which is rarely needed but not recoverable if a caller wanted it.
Used by 3 apps in this directory
Fern
Developer Tools
Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.
Latitude
AI Agents · Monitoring
Open-source AI agent monitoring that catches what will break next before your users do.
PostHog
Analytics · Monitoring · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.