raxx v0.11.1 Raxx.Location
Manipulate location header on raxx messages
Summary
Functions
Read location of the HTTP message.
Examples
iex> %Raxx.Request{headers: [{"location", "http://www.example.com"}]} |> Raxx.Location.fetch
{:ok, %URI{authority: "www.example.com", fragment: nil,
host: "www.example.com", path: nil, port: 80, query: nil,
scheme: "http", userinfo: nil}}
iex> %Raxx.Request{headers: []} |> Raxx.Location.fetch
{:error, :field_value_not_specified}
iex> %Raxx.Request{headers: [{"location", "http://www.example.com"}, {"location", "http://www.example.org"}]} |> Raxx.Location.fetch
{:error, :duplicated_field}
Set the location of a HTTP message.
Examples
iex> %Raxx.Request{} |> Raxx.Location.set("www.example.com") |> Map.get(:headers)
[{"location", "www.example.com"}]
iex> uri = %URI{authority: "www.example.com", fragment: nil,
iex> host: "www.example.com", path: nil, port: 80, query: nil,
iex> scheme: "http", userinfo: nil}
iex> %Raxx.Request{} |> Raxx.Location.set(uri) |> Map.get(:headers)
[{"location", "http://www.example.com"}]
iex> %Raxx.Request{headers: [{"location", "www.example.com"}]} |> Raxx.Location.set("www.example.org") |> Map.get(:headers)
[{"location", "www.example.org"}]