pub fn parse_range<'a>(
value: &'a [u8],
limits: &Limits,
) -> Result<MediaRange<'a>, ParseError>Expand description
Parses a media range, as in one member of Accept: */*, type/*, or a
media type, with an optional weight.
The first parameter named q (ASCII case-insensitive) is the weight; it
and every parameter after it are accept-ext and take no part in
matching (RFC 9110 section 12.5.1). A range without q has weight 1.
§Errors
ErrorKind::Wildcard for */subtype; ErrorKind::InvalidQValue;
the errors of parse.
§Examples
use parse_net::{media, Limits};
let r = media::parse_range(b"text/*;q=0.5", &Limits::DEFAULT)?;
assert_eq!((r.specificity(), r.weight().thousandths()), (2, 500));
let html = parse_net::parse_media_type(b"text/html")?;
assert!(r.matches(&html));
assert!(media::parse_range(b"*/html", &Limits::DEFAULT).is_err());