Skip to main content

Crate philiprehberger_typed_headers

Crate philiprehberger_typed_headers 

Source
Expand description

Strongly-typed HTTP header parsing and construction for common headers

This crate provides type-safe representations of frequently used HTTP headers, with parsing from raw strings and serialization back to valid header values.

No external dependencies — std only.

§Supported Headers

  • ContentType — Content-Type with media type, subtype, and parameters
  • CacheControl — Cache-Control directives with builder pattern
  • Authorization — Bearer, Basic, and custom auth schemes
  • Accept — Accept header with quality-based content negotiation
  • SetCookie — Set-Cookie with all standard attributes
  • ContentDisposition — Content-Disposition for inline/attachment
  • ETag — ETag with strong and weak comparison

§Example

use philiprehberger_typed_headers::{ContentType, CacheControl, Authorization};

let ct = ContentType::parse("application/json; charset=utf-8").unwrap();
assert_eq!(ct.mime_type(), "application/json");
assert_eq!(ct.charset(), Some("utf-8"));

let cc = CacheControl::new().no_cache().max_age(3600);
assert_eq!(cc.to_string(), "no-cache, max-age=3600");

let auth = Authorization::bearer("my-token");
assert_eq!(auth.to_string(), "Bearer my-token");

Structs§

Accept
A parsed Accept header with content negotiation support.
CacheControl
A parsed Cache-Control header with builder pattern support.
ContentDisposition
A parsed Content-Disposition header.
ContentType
A parsed Content-Type header.
ETag
A parsed ETag header with strong and weak comparison.
MediaRange
A single media range entry within an Accept header.
SetCookie
A parsed Set-Cookie header with builder support.

Enums§

Authorization
A parsed Authorization header.
HeaderError
Error type returned when a header string cannot be parsed.
SameSite
The SameSite cookie attribute.