Add helper function to convert single IPs into CIDR format if they were not provided that way
This commit is contained in:
parent
241f7cb1ed
commit
35ee759e74
1 changed files with 12 additions and 1 deletions
|
@ -47,8 +47,19 @@ defmodule Pleroma.Plugs.RemoteIp do
|
||||||
config
|
config
|
||||||
|> Keyword.get(:proxies, [])
|
|> Keyword.get(:proxies, [])
|
||||||
|> Enum.concat(reserved)
|
|> Enum.concat(reserved)
|
||||||
|> Enum.map(&InetCidr.parse/1)
|
|> Enum.map(&maybe_add_cidr/1)
|
||||||
|
|
||||||
{headers, proxies}
|
{headers, proxies}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp maybe_add_cidr(proxy) when is_binary(proxy) do
|
||||||
|
proxy =
|
||||||
|
cond do
|
||||||
|
"/" in String.codepoints(proxy) -> proxy
|
||||||
|
InetCidr.v4?(InetCidr.parse_address!(proxy)) -> proxy <> "/32"
|
||||||
|
InetCidr.v6?(InetCidr.parse_address!(proxy)) -> proxy <> "/128"
|
||||||
|
end
|
||||||
|
|
||||||
|
InetCidr.parse(proxy)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue