Skip to main content

Crate content_type

Crate content_type 

Source
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§

ContentType
A parsed Content-Type: a media type plus its parameters.

Enums§

FormatError
An error from format.

Functions§

format
Format a ContentType into a header string, validating the type and parameters.
parse
Parse a Content-Type header value (lenient: never errors).
parse_with
Parse a Content-Type header value, optionally skipping parameters.