View Source HTTPSpec.Header (http_spec v3.0.0)
Helpers for handling headers.
Summary
Functions
Deletes the header given by name
.
Returns the values of the header specified by name
.
Puts the given value
under name
.
Puts the given value
under name
unless already present.
Lazy version of put_new_header/3
.
Types
@type headers() :: [HTTPSpec.field()]
Functions
@spec delete_header(HTTPSpec.message(), binary()) :: HTTPSpec.message()
Deletes the header given by name
.
All occurrences of the header are deleted, in case the header is repeated multiple times.
Examples
iex> HTTPSpec.Header.get_header(request, "cache-control")
["max-age=600", "no-transform"]
iex> request = Request.delete_header(req, "cache-control")
iex> HTTPSpec.Header.get_header(request, "cache-control")
[]
@spec get_header(HTTPSpec.message(), binary()) :: [binary()]
Returns the values of the header specified by name
.
Examples
iex> HTTPSpec.Header.get_header(request, "accept")
["application/json"]
iex> HTTPSpec.Header.get_header(requset, "x-unknown")
[]
@spec put_header(HTTPSpec.message(), binary(), binary()) :: HTTPSpec.message()
Puts the given value
under name
.
If the header was previously set, its value is overwritten.
Examples
iex> HTTPSpec.Header.get_header(request, "accept")
[]
iex> request = Request.put_header(request, "accept", "application/json")
iex> HTTPSpec.Header.get_header(request, "accept")
["application/json"]
@spec put_new_header(HTTPSpec.message(), binary(), binary()) :: HTTPSpec.message()
Puts the given value
under name
unless already present.
See put_header/3
for more information.
Examples
iex> request =
...> request
...> |> HTTPSpec.Header.put_new_header("accept", "application/json")
...> |> HTTPSpec.Header.put_new_header("accept", "text/html")
iex> HTTPSpec.Header.get_header(request, "accept")
["application/json"]
@spec put_new_lazy_header( HTTPSpec.message(), binary(), (-> binary()) | (HTTPSpec.message() -> binary()) ) :: HTTPSpec.message()
Lazy version of put_new_header/3
.