Crate uhttp_media_type [] [src]

This crate provides a zero-allocation, slice-based parser for HTTP Media Types as they appear in Content-Type and Accept headers.

Example

use uhttp_media_type::{MediaType, MediaParams, ParamValue};

let mt = MediaType::new("application/json; charset=utf-8; param=\"a value\"").unwrap();
assert_eq!(mt.mimetype, "application/json");
assert_eq!(mt.parts().unwrap(), ("application", "json"));
assert_eq!(mt.params, " charset=utf-8; param=\"a value\"");

let mut params = MediaParams::new(mt.params);

let (key, val) = params.next().unwrap().unwrap();
assert_eq!(key, "charset");
assert_eq!(val, ParamValue::Unquoted("utf-8"));
assert_eq!(val.inner(), "utf-8");

let (key, val) = params.next().unwrap().unwrap();
assert_eq!(key, "param");
assert_eq!(val, ParamValue::Quoted("a value"));
assert_eq!(val.inner(), "a value");

assert!(params.next().is_none());

Structs

MediaParams

Iterator over key/value pairs in a media type parameter string.

MediaType

Parses a media type field into its MIME type and parameter components.

Enums

ParamValue

A value for a media type parameter.