Skip to content

Commit 65db4dd

Browse files
committed
Update docs
1 parent 14effe5 commit 65db4dd

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ See the [Documentation][docs] on HexDocs.
2828

2929
## Installation
3030

31-
Add `safeurl` to your project dependencies in `mix.exs`:
31+
To get started, add `safeurl` to your project dependencies in `mix.exs`. Optionally, you may
32+
also add `HTTPoison` to your dependencies for making requests directly through SafeURL:
3233

3334
```elixir
3435
def deps do
35-
[{:safeurl, "~> 0.2.0"}]
36+
[
37+
{:safeurl, "~> 0.2.0"},
38+
{:httpoison, "~> 1.8"}, # Optional
39+
]
3640
end
3741
```
3842

@@ -47,9 +51,9 @@ end
4751
CIDR ranges to the blocklist, or alternatively allow specific CIDR ranges to which the
4852
application is allowed to make requests.
4953

50-
You can use `allowed?/2` or `validate/2` to check if a URL is safe to call, or just call
51-
it directly via `get/4` which will validate it automatically before calling, and return an
52-
error if it is not.
54+
You can use `allowed?/2` or `validate/2` to check if a URL is safe to call, or if you have
55+
the `HTTPoison` application available, just call it directly via `get/4` which will validate
56+
it automatically before calling, and return an error if it is not.
5357

5458

5559
### Examples
@@ -67,6 +71,8 @@ iex> SafeURL.validate("http://230.10.10.10/")
6771
iex> SafeURL.validate("http://230.10.10.10/", block_reserved: false)
6872
:ok
6973

74+
# When HTTPoison is available:
75+
7076
iex> SafeURL.get("https://10.0.0.1/ssrf.txt")
7177
{:error, :restricted}
7278

lib/safeurl.ex

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ defmodule SafeURL do
88
allowed to make requests.
99
1010
You can use `allowed?/2` or `validate/2` to check if a
11-
URL is safe to call, or just call it directly via `get/4`
12-
which will validate it automatically before calling, and
13-
return an error if it is not.
11+
URL is safe to call. If the `HTTPoison` application is
12+
available, you can also call `get/4` directly which will
13+
validate the host before making an HTTP request.
1414
1515
1616
## Examples
@@ -27,6 +27,8 @@ defmodule SafeURL do
2727
iex> SafeURL.validate("http://230.10.10.10/", block_reserved: false)
2828
:ok
2929
30+
# If HTTPoison is available:
31+
3032
iex> SafeURL.get("https://10.0.0.1/ssrf.txt")
3133
{:error, :restricted}
3234
@@ -190,7 +192,8 @@ defmodule SafeURL do
190192
return `{:error, :restricted}`.
191193
192194
`headers` and `httpoison_options` will be passed directly to
193-
`HTTPoison` when the request is executed.
195+
`HTTPoison` when the request is executed. This function will
196+
raise if `HTTPoison` if not available.
194197
195198
See `allowed?/2` for more details on URL validation.
196199
@@ -211,7 +214,7 @@ defmodule SafeURL do
211214
212215
"""
213216
@spec get(binary(), Keyword.t(), HTTPoison.headers(), Keyword.t()) ::
214-
{:ok, HTTPoison.Response.t()} | {:error, :restricted}
217+
{:ok, HTTPoison.Response.t()} | {:error, :restricted} | no_return()
215218
def get(url, options \\ [], headers \\ [], httpoison_options \\ []) do
216219
unless function_exported?(HTTPoison, :get, 3) do
217220
raise "HTTPoison.get/3 not available"

0 commit comments

Comments
 (0)