Expand description
§content-type — parse and format Content-Type headers
Parse an HTTP Content-Type / media-type header value into its type and
parameters, and format one back out, following RFC 9110. A faithful Rust port of
the content-type npm package
(v2.0.0): a lenient parse and a strict, validating format. Zero
dependencies and #![no_std].
use content_type::{parse, format, ContentType};
let ct = parse("text/html; charset=utf-8");
assert_eq!(ct.type_, "text/html");
assert_eq!(ct.get_parameter("charset"), Some("utf-8"));
let ct = ContentType::new("application/json").with_parameter("charset", "utf-8");
assert_eq!(format(&ct).unwrap(), "application/json; charset=utf-8");Structs§
- Content
Type - A parsed
Content-Type: a media type plus its parameters.
Enums§
- Format
Error - An error from
format.
Functions§
- format
- Format a
ContentTypeinto a header string, validating the type and parameters. - parse
- Parse a
Content-Typeheader value (lenient: never errors). - parse_
with - Parse a
Content-Typeheader value, optionally skipping parameters.