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 parametersCacheControl— Cache-Control directives with builder patternAuthorization— Bearer, Basic, and custom auth schemesAccept— Accept header with quality-based content negotiationSetCookie— Set-Cookie with all standard attributesContentDisposition— Content-Disposition for inline/attachmentETag— 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.
- Cache
Control - A parsed Cache-Control header with builder pattern support.
- Content
Disposition - A parsed Content-Disposition header.
- Content
Type - A parsed Content-Type header.
- ETag
- A parsed ETag header with strong and weak comparison.
- Media
Range - A single media range entry within an Accept header.
- SetCookie
- A parsed Set-Cookie header with builder support.
Enums§
- Authorization
- A parsed Authorization header.
- Header
Error - Error type returned when a header string cannot be parsed.
- Same
Site - The
SameSitecookie attribute.