@@ -8,9 +8,9 @@ defmodule SafeURL do
8
8
allowed to make requests.
9
9
10
10
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 .
14
14
15
15
16
16
## Examples
@@ -27,6 +27,8 @@ defmodule SafeURL do
27
27
iex> SafeURL.validate("http://230.10.10.10/", block_reserved: false)
28
28
:ok
29
29
30
+ # If HTTPoison is available:
31
+
30
32
iex> SafeURL.get("https://10.0.0.1/ssrf.txt")
31
33
{:error, :restricted}
32
34
@@ -190,7 +192,8 @@ defmodule SafeURL do
190
192
return `{:error, :restricted}`.
191
193
192
194
`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.
194
197
195
198
See `allowed?/2` for more details on URL validation.
196
199
@@ -211,8 +214,11 @@ defmodule SafeURL do
211
214
212
215
"""
213
216
@ 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 ( )
215
218
def get ( url , options \\ [ ] , headers \\ [ ] , httpoison_options \\ [ ] ) do
219
+ unless function_exported? ( HTTPoison , :get , 3 ) do
220
+ raise "HTTPoison.get/3 not available"
221
+ end
216
222
with :ok <- validate ( url , options ) do
217
223
HTTPoison . get ( url , headers , httpoison_options )
218
224
end
0 commit comments