remote_ip v0.1.1 RemoteIp.Headers.Generic

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.

Summary

Functions

Parses a comma-separated list of IPs

Types

header()
ip()
ip :: :inet.ip_address

Functions

parse(header)
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")
[]