Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get reserved list from option #11

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/remote_ip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ defmodule RemoteIp do
def init(opts \\ []) do
headers = Keyword.get(opts, :headers, @headers)
headers = MapSet.new(headers)
proxies = Keyword.get(opts, :proxies, @proxies) ++ @reserved
reserved = Keyword.get(opts, :reserved, @reserved)
proxies = Keyword.get(opts, :proxies, @proxies) ++ reserved
proxies = proxies |> Enum.map(&InetCidr.parse/1)

{headers, proxies}
Expand All @@ -75,7 +76,7 @@ defmodule RemoteIp do
def call(conn, {headers, proxies}) do
case last_forwarded_ip(conn, headers, proxies) do
nil -> conn
ip -> %{conn | remote_ip: ip}
ip -> %{conn | remote_ip: ip}
end
end

Expand All @@ -91,7 +92,7 @@ defmodule RemoteIp do

defp last_ip_forwarded_through(ips, proxies) do
ips
|> Enum.reverse
|> Enum.reverse()
|> Enum.find(&forwarded?(&1, proxies))
end

Expand Down