1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-11-19 03:19:17 +00:00

Add helper function to convert single IPs into CIDR format if they were not provided that way

This commit is contained in:
Mark Felder 2020-10-05 11:48:41 -05:00
parent 241f7cb1ed
commit 35ee759e74

View file

@ -47,8 +47,19 @@ defp remote_ip_opts(config) do
config
|> Keyword.get(:proxies, [])
|> Enum.concat(reserved)
|> Enum.map(&InetCidr.parse/1)
|> Enum.map(&maybe_add_cidr/1)
{headers, proxies}
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