header-tools 0.1.0
Parse HTTP headers: Accept q-values and negotiation, Content-Type parameters, Link, and Basic or Bearer Authorization
Install
cargo add header-tools --registry rupm
In Ruststudio: Packages, search for header-tools, Install.
Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-22.
Versions
- 0.1.0 2026-11-22
README
# header-tools
Parse HTTP headers: Accept q-values and negotiation, Content-Type parameters, Link, and Basic or Bearer Authorization
Add it with `rupm add header-tools` (or `cargo add header-tools --registry rupm`).
```rust
use header_tools::*;
let accept = parse_accept("text/html, application/json;q=0.9, */*;q=0.1");
assert_eq!(accept[1].q, 0.9);
assert_eq!(negotiate("application/json;q=0.5, text/html;q=0.9", &["application/json", "text/html"]), Some("text/html"));
let ct = parse_content_type("Text/HTML; charset=\"UTF-8\"").unwrap();
assert_eq!(ct.media_type, "text/html");
assert_eq!(ct.charset(), Some("UTF-8"));
assert_eq!(
parse_authorization("Bearer abc.def"),
Some(Authorization::Bearer("abc.def".to_string()))
);
let links = parse_link("<https://x/?page=2>; rel=\"next\"");
assert_eq!(links[0].rel.as_deref(), Some("next"));
```