remote_ip v0.2.0 RemoteIp.Headers.Generic View Source

Generic parser for forwarding headers.

When there is no other special RemoteIp.Headers.* parser submodule, RemoteIp.Headers.parse/2 will use this module to parse the header value. So, RemoteIp.Headers.Generic is used to parse X-Forwarded-For, X-Real-IP, X-Client-IP, and generally unrecognized headers.

Link to this section Summary

Functions

Parses a comma-separated list of IPs.

Link to this section Types

Link to this section Functions

Link to this function

parse(header)

View Source
parse(header()) :: [ip()]

Parses a comma-separated list of IPs.

Any amount of whitespace is allowed before and after the commas, as well as at the beginning/end of the input.

Examples

iex> RemoteIp.Headers.Generic.parse("1.2.3.4, 5.6.7.8")
[{1, 2, 3, 4}, {5, 6, 7, 8}]

iex> RemoteIp.Headers.Generic.parse("  ::1  ")
[{0, 0, 0, 0, 0, 0, 0, 1}]

iex> RemoteIp.Headers.Generic.parse("invalid")
[]