Skip to main content

Module media

Module media 

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

Boundary
A validated multipart boundary, unquoted.
MediaRange
A validated media range from Accept.
MediaType
A validated media type.

Functions§

parse
Parses a media type, as in Content-Type.
parse_media_type
Parses a Content-Type style media type with the default Limits.
parse_range
Parses a media range, as in one member of Accept: */*, type/*, or a media type, with an optional weight.
write
Writes type/subtype and then ; name=value for each pair, values as a token when they are one and as a quoted string otherwise.