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

Pick the best media type the server can produce, given the client’s Accept header value and the list of types the server supports.

accept is the raw header value (e.g. "application/json,text/html;q=0.9,*/*;q=0.5"). available is the ordered list of types the server can serve.

Matching rules:

  • Exact match wins over wildcard match
  • Higher q-value wins over lower
  • Server’s available order breaks ties at equal q
  • Returns None only when available is empty or no client preference matches (a */* client preference will always match the first available type)