|
44 | 44 | %% @doc Atoms used to identify messages in {active, once | true} mode. |
45 | 45 | messages(_) -> {ssl, ssl_closed, ssl_error}. |
46 | 46 |
|
| 47 | +%% @doc The ssl:connect/4 (and related) doesn't work with textual representation |
| 48 | +%% of IP addresses. It accepts either a string with a DNS-resolvable name or a |
| 49 | +%% tuple with parts of an IP as numbers. This function attempts to parse given |
| 50 | +%% string and either returns such tuple, or the string if it's impossible to |
| 51 | +%% parse. |
| 52 | +parse_address(Host) when is_list(Host) -> |
| 53 | + case inet:parse_address(Host) of |
| 54 | + {ok, Address} -> Address; |
| 55 | + {error, _} -> Host |
| 56 | + end. |
| 57 | + |
| 58 | + |
47 | 59 | connect(Host, Port, Opts) -> |
48 | 60 | connect(Host, Port, Opts, infinity). |
49 | 61 |
|
50 | 62 | connect(Host, Port, Opts, Timeout) when is_list(Host), is_integer(Port), |
51 | 63 | (Timeout =:= infinity orelse is_integer(Timeout)) -> |
| 64 | + |
52 | 65 | BaseOpts = [binary, {active, false}, {packet, raw}, |
53 | 66 | {secure_renegotiate, true}, |
54 | 67 | {reuse_sessions, true}, |
55 | 68 | {honor_cipher_order, true}, |
56 | 69 | {versions,['tlsv1.2', 'tlsv1.1', tlsv1, sslv3]}, |
57 | 70 | {ciphers, ciphers()}], |
58 | 71 | Opts1 = hackney_util:merge_opts(BaseOpts, Opts), |
59 | | - |
| 72 | + Host1 = parse_address(Host), |
60 | 73 | %% connect |
61 | | - ssl:connect(Host, Port, Opts1, Timeout). |
| 74 | + ssl:connect(Host1, Port, Opts1, Timeout). |
62 | 75 |
|
63 | 76 |
|
64 | 77 | ciphers() -> |
|
0 commit comments