Expand description
Content negotiation: quality values and the selection of the best offer
for Accept, Accept-Language, Accept-Encoding, and Accept-Charset
(RFC 9110 section 12, RFC 4647).
Every selection walks the request’s members against the server’s offers
with no allocation: offers are taken 32 at a time, and the members are
read once per group of 32 (work is members times offers, with members
bounded by Limits::max_list_members).
§Examples
use parse_net as pn;
let chrome = b"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
assert_eq!(pn::best_media(Some(chrome), &["application/json", "text/html"]), Some(1));
assert_eq!(pn::best_language(Some(b"en-US, fr;q=0.8"), &["fr", "en"]), Some(1));
assert_eq!(pn::best_encoding(Some(b"gzip, br;q=0.9"), &["br", "gzip"]), Some(1));Structs§
- Accept
List - The media ranges of a validated
Acceptvalue. - Negotiator
- The configurable form of the
best_*functions. - QValue
- A quality value: 0 to 1 in thousandths (RFC 9110 section 12.4.2). No floating point.
- Weighted
- One member of a weighted list: a value, its weight, and its parameters.
- Weighted
List - The members of a validated weighted list.
Enums§
- Language
Matching - How
Accept-Languageranges are matched against offered tags. - Malformed
Policy - What a selection does with a header that does not parse.
- Outcome
- The result of a selection.
Functions§
- best_
charset - Selects the best charset for
Accept-Charset. - best_
encoding - Selects the best content coding for
Accept-Encoding. - best_
language - Selects the best language for
Accept-Languagewith RFC 4647 lookup. - best_
media - Selects the best media type for
Acceptwith the defaults. - parse_
accept - Parses
Acceptinto its media ranges. - parse_
weighted - Parses
token *( OWS ";" OWS parameter )members with weights, as inAccept-Encoding,Accept-Charset, andAccept-Language.