Skip to main content

parse_accept

Function parse_accept 

Source
pub fn parse_accept(raw: Option<&str>) -> Accept
Expand description

Parse an Accept header into a coarse preference.

Deliberately not the accept.contains("application/json") check used by the admin’s own fetch() helpers (crate::admin::handlers::wants_json_response). That test is fine for a request the admin JS made itself, but wrong on a public URL: it flips to JSON on text/html, application/json;q=0.1, where the client clearly prefers HTML, and it treats application/json;q=0 — an explicit refusal — as a request for JSON.

Quality values are honoured, q=0 rejects a type outright, and a more specific range outranks a wildcard at equal q. A tie goes to HTML, so a browser sending text/html,…,*/*;q=0.8 can never be handed a JSON body.