Skip to content

Commit ce1aa51

Browse files
committed
Updte DNS module and DNSResolver behaviour
1 parent a7bc0b6 commit ce1aa51

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Diff for: guides/migrating_to_1.0.md

+12
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ iex> Application.put_env(:safeurl, :detailed_error, false)
2828
iex> SafeURL.validate("http://localhost")
2929
{:error, :restricted}
3030
```
31+
32+
### Change modules implementing `SafeURL.DNSResolver` behaviour
33+
34+
If you have a module that implements `SafeURL.DNSResolver` behaviour, note that
35+
`DNSResolver.resolve/1` signature has changed. Specifically, the ok tuple should now
36+
always return a list of IPs. A single IP is not a valid return type:
37+
38+
```elixir
39+
# DNS is the default implementation
40+
iex> DNS.resolve("wikipedia.org")
41+
{:ok, [{198, 35, 26, 96}]}
42+
```

Diff for: lib/safeurl/dns_resolver.ex

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,5 @@ defmodule SafeURL.DNSResolver do
6969
7070
"""
7171

72-
@type resolution :: :inet.ip() | [:inet.ip()]
73-
@callback resolve(host :: binary()) :: {:ok, resolution()} | {:error, atom()}
72+
@callback resolve(host :: String.t()) :: {:ok, list()} | {:error, :inet_res.res_error()}
7473
end

Diff for: lib/safeurl/safeurl.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ defmodule SafeURL do
239239
{:error, :einval} ->
240240
# TODO: safely handle multiple IPs/round-robin DNS
241241
case dns_module.resolve(hostname) do
242-
{:ok, ips} -> ips |> List.wrap() |> List.first()
242+
{:ok, [ip | _]} -> ip
243243
{:error, _reason} -> nil
244244
end
245245
end

Diff for: mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ defmodule SafeURL.MixProject do
5454
[
5555
{:httpoison, "~> 1.0 or ~> 2.0", optional: true},
5656
{:inet_cidr, "~> 1.0 and >= 1.0.6"},
57-
{:dns, "~> 2.2"},
57+
{:dns, "~> 2.4"},
5858
{:tesla, "~> 1.0", optional: true},
5959
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
6060
]

0 commit comments

Comments
 (0)