plug_best v0.1.3 PlugBest

A library that parses HTTP Accept-* headers and returns the best match based on a list of values.

Examples

iex> conn = %Plug.Conn{req_headers: [{"accept-language", "fr-CA,fr;q=0.8,en;q=0.6,en-US;q=0.4"}]}
iex> conn |> PlugBest.best_language(["en", "fr"])
{"fr-CA", "fr", 1.0}

iex> conn = %Plug.Conn{req_headers: [{"accept-language", "es"}]}
iex> conn |> PlugBest.best_language(["fr", "ru"])
nil

iex> conn = %Plug.Conn{req_headers: [{"accept-language", "es"}]}
iex> conn |> PlugBest.best_language_or_first(["ru", "fr"])
{"ru", "ru", 0.0}

Summary

Functions

Returns the best supported langage based on the connection Accept-Language HTTP header. Returns nil if none is found

Returns the best supported langage based on the connection Accept-Language HTTP header. Returns the first supported language if none is found

Functions

best_language(conn, supported_languages)

Returns the best supported langage based on the connection Accept-Language HTTP header. Returns nil if none is found.

best_language_or_first(conn, supported_languages)

Returns the best supported langage based on the connection Accept-Language HTTP header. Returns the first supported language if none is found.