Use CF-Connecting-IP when present for remote IP address
parent
0799138622
commit
5efa15f381
@ -1,13 +1,19 @@
|
||||
defmodule PlausibleWeb.RemoteIp do
|
||||
def get(conn) do
|
||||
cf_connecting_ip = List.first(Plug.Conn.get_req_header(conn, "cf-connecting-ip"))
|
||||
forwarded_for = List.first(Plug.Conn.get_req_header(conn, "x-forwarded-for"))
|
||||
|
||||
if forwarded_for do
|
||||
String.split(forwarded_for, ",")
|
||||
|> Enum.map(&String.trim/1)
|
||||
|> List.first()
|
||||
else
|
||||
to_string(:inet_parse.ntoa(conn.remote_ip))
|
||||
cond do
|
||||
cf_connecting_ip ->
|
||||
cf_connecting_ip
|
||||
|
||||
forwarded_for ->
|
||||
String.split(forwarded_for, ",")
|
||||
|> Enum.map(&String.trim/1)
|
||||
|> List.first()
|
||||
|
||||
true ->
|
||||
to_string(:inet_parse.ntoa(conn.remote_ip))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue