From d7c0d1e10769e26980e2d2989e5a5bdd176b79af Mon Sep 17 00:00:00 2001 From: Julius Andrikonis Date: Tue, 13 Feb 2024 12:31:31 +0200 Subject: [PATCH] Fix options that conflict with OTP's ssl library --- src/hackney_ssl.erl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/hackney_ssl.erl b/src/hackney_ssl.erl index 5b65e4a6..0a3b7319 100644 --- a/src/hackney_ssl.erl +++ b/src/hackney_ssl.erl @@ -136,9 +136,23 @@ connect(Host, Port, Opts) -> connect(Host, Port, Opts, Timeout) when is_list(Host), is_integer(Port), (Timeout =:= infinity orelse is_integer(Timeout)) -> - BaseOpts = [binary, {active, false}, {packet, raw}, + Protocol = proplists:get_value(protocol, Opts, tls), + AdditionalOptsNeeded = case Protocol of + tls -> + DefaultVersions = lists:map(fun tls_record:protocol_version/1, tls_record:supported_protocol_versions()), + Versions = proplists:get_value(versions, Opts, DefaultVersions), + lists:any(fun(Version) -> lists:member(Version, ['tlsv1','tlsv1.1','tlsv1.2']) end, Versions); + _ -> + true + end, + BaseOpts = [binary, {active, false}, {packet, raw}] ++ + case AdditionalOptsNeeded of + true -> [ {secure_renegotiate, true}, - {reuse_sessions, true}], + {reuse_sessions, true}]; + false -> + [] + end, Opts1 = hackney_util:merge_opts(BaseOpts, Opts), %% connect ssl:connect(parse_address(Host), Port, Opts1, Timeout).