Expand description
Media types: type "/" subtype parameters (RFC 9110 section 8.3.1), and
the RFC 2046 multipart boundary.
Type, subtype, and parameter names are case-insensitive; parameter values
are case-sensitive unless the parameter’s definition says otherwise
(charset is case-insensitive, RFC 9110 section 8.3.2).
§Examples
use parse_net as pn;
let mt = pn::parse_media_type(b"Multipart/Form-Data; boundary=\"----x y\"")?;
assert!(mt.is_multipart_form_data() && mt.is("multipart", "form-data"));
assert_eq!(mt.boundary()?.map(|b| b.as_bytes()), Some(&b"----x y"[..]));
assert_eq!(pn::parse_media_type(b"text/*").unwrap_err().kind(), pn::ErrorKind::Wildcard);
let mut buf = [0u8; 64];
let mut out = pn::SliceSink::new(&mut buf);
pn::media::write("text", "plain", &[("charset", "utf-8")], &mut out)?;
assert_eq!(out.written(), b"text/plain; charset=utf-8");Structs§
Functions§
- parse
- Parses a media type, as in
Content-Type. - parse_
media_ type - Parses a
Content-Typestyle media type with the defaultLimits. - write
- Writes
type/subtypeand then; name=valuefor each pair, values as a token when they are one and as a quoted string otherwise.