View Source RemoteIp.Parsers.Generic (remote_ip v1.2.0)
Generic parser for forwarding headers.
This module implements the RemoteIp.Parser
behaviour. When there is not a
more specific parser, RemoteIp.Headers.parse/1
falls back to using this
one.
The value is parsed simply as a comma-separated list of IPs. This is suitable
for a wide range of headers, such as X-Forwarded-For
, X-Real-IP
, and
X-Client-IP
.
Any amount of whitespace is allowed before and after the commas, as well as at the beginning & end of the input.
Examples
iex> RemoteIp.Parsers.Generic.parse("1.2.3.4, 5.6.7.8")
[{1, 2, 3, 4}, {5, 6, 7, 8}]
iex> RemoteIp.Parsers.Generic.parse(" ::1 ")
[{0, 0, 0, 0, 0, 0, 0, 1}]
iex> RemoteIp.Parsers.Generic.parse("invalid")
[]