Skip to main content

negotiate

Function negotiate 

Source
pub fn negotiate<'a, S: AsRef<str>>(
    accept: &str,
    available: &'a [S],
) -> Option<&'a str>
Expand description

Choose the media type to send back.

accept is the raw header, such as "application/json,text/html;q=0.9,*/*;q=0.5". available is what your handler can produce, best first.

Each type takes the q of the most specific range that matches it (RFC 9110 §12.5.1), whatever the header order; q=0 means “not acceptable”. A higher q wins; at the same q an exact match beats a wildcard; after that the order of available decides. Returns None when available is empty or nothing on offer is acceptable.