Skip to main content

Module negotiate

Module negotiate 

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

AcceptList
The media ranges of a validated Accept value.
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.
WeightedList
The members of a validated weighted list.

Enums§

LanguageMatching
How Accept-Language ranges are matched against offered tags.
MalformedPolicy
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-Language with RFC 4647 lookup.
best_media
Selects the best media type for Accept with the defaults.
parse_accept
Parses Accept into its media ranges.
parse_weighted
Parses token *( OWS ";" OWS parameter ) members with weights, as in Accept-Encoding, Accept-Charset, and Accept-Language.