|
1 | 1 | if Code.ensure_loaded?(HTTPoison) do |
2 | 2 | defmodule SafeURL.HTTPoison do |
| 3 | + @moduledoc since: "1.0.0" |
3 | 4 | @moduledoc """ |
4 | 5 | A utility module that should be a drop-in replacement for `HTTPoison`. Only |
5 | 6 | supports `get/3`. |
6 | 7 | """ |
7 | 8 |
|
| 9 | + @doc since: "1.0.0" |
8 | 10 | @doc """ |
9 | 11 | Validate a URL and execute a GET request using `HTTPoison`. |
10 | 12 |
|
11 | 13 | If the URL is safe, this function will execute the request using |
12 | 14 | `HTTPoison`, returning the result directly. Otherwise, it will |
13 | | - return `{:error, :restricted}`. |
| 15 | + return error. |
14 | 16 |
|
15 | 17 | `headers` and `options` will be passed directly to |
16 | | - `HTTPoison` when the request is executed. This function will |
17 | | - raise if `HTTPoison` if not available. |
| 18 | + `HTTPoison` when the request is executed. |
18 | 19 |
|
19 | 20 | ## Examples |
20 | 21 |
|
21 | 22 | iex> SafeURL.HTTPoison.get("https://10.0.0.1/ssrf.txt") |
22 | | - {:error, :restricted} |
| 23 | + {:error, :unsafe_reserved} |
23 | 24 |
|
24 | 25 | iex> SafeURL.HTTPoison.get("https://google.com/") |
25 | 26 | {:ok, %HTTPoison.Response{...}} |
26 | 27 |
|
27 | | - iex> SafeURL.HTTPoison.get("https://google.com/", schemes: ~w[ftp]) |
28 | | - {:error, :restricted} |
29 | | -
|
30 | 28 | """ |
31 | 29 | @spec get(binary(), HTTPoison.headers(), Keyword.t()) :: |
32 | | - {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} | {:error, :restricted} |
| 30 | + {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} | {:error, SafeURL.error()} | {:error, :restricted} |
33 | 31 | def get(url, headers \\ [], options \\ []) do |
34 | 32 | with :ok <- SafeURL.validate(url) do |
35 | 33 | HTTPoison.get(url, headers, options) |
|
0 commit comments