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.

Types

@type headers() :: [HTTPSpec.field()]

Functions

Link to this function

delete_header(message, name)

View Source
@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")
[]
Link to this function

get_header(message, name)

View Source
@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")
[]
Link to this function

put_header(message, name, value)

View Source
@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"]
Link to this function

put_new_header(message, name, value)

View Source
@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"]
Link to this function

put_new_lazy_header(message, name, fun)

View Source
@spec put_new_lazy_header(
  HTTPSpec.message(),
  binary(),
  (-> binary()) | (HTTPSpec.message() -> binary())
) :: HTTPSpec.message()

Lazy version of put_new_header/3.