View Source accept_header (accept v0.3.6)
HTTP Accept header parser and content-type negotiation helper
Summary
Functions
Negotiates the most appropriate content_type given the accept header and a list of alternatives.
Parses Accept header, returns a list of media_ranges.
Functions
-spec negotiate(Header, Alternatives) -> Match when Header :: BinaryOrString, Alternatives :: [Alternative], Alternative :: BinaryOrString | {BinaryOrString, Tag}, BinaryOrString :: binary() | string(), Tag :: any(), Match :: Tag | nomatch.
Negotiates the most appropriate content_type given the accept header and a list of alternatives.
accept_header:negotiate(\"text/*;q=0.3, text/html;q=0.7, text/html;level=1,\"
\"text/html;level=2;q=0.4, */*;q=0.5\",
[\"text/html;level=2\", \"text/html;level-3\"]).
\"text/html;level-3\"
-spec parse(AcceptString) -> Result when AcceptString :: binary() | string(), Result :: [accept_encoding_header:media_range()].
Parses Accept header, returns a list of media_ranges.
accept_header:parse(\"text/*;q=0.3, text/html;q=0.7, text/html;level=1,\"
\"text/html;level=2;q=0.4, */*;q=0.5\").
[{media_range,\"text\",\"*\",0.3,[]},
{media_range,\"text\",\"html\",0.7,[]},
{media_range,\"text\",\"html\",1,[{\"level\",\"1\"}]},
{media_range,\"text\",\"html\",0.4,[{\"level\",\"2\"}]},
{media_range,\"*\",\"*\",0.5,[]}]