Skip to content

Commit

Permalink
Merge pull request #22 from egobrain/feature/ssl-options
Browse files Browse the repository at this point in the history
Add ssl_options. Fix manual address family tcp options.
  • Loading branch information
Evgeny Bob authored Nov 7, 2018
2 parents 41da765 + 84fb382 commit 4ac71aa
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/lhttpc_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,24 @@ execute(From, Host, Port, Ssl, Path, Method, Hdrs0, Body, Options) ->
DefOptions = proplists:unfold(application:get_env(lhttpc, connect_options, [])),
DefTimeout = proplists:get_value(connect_timeout, DefOptions, infinity),
UserOptions = proplists:unfold(proplists:get_value(connect_options, Options, [])),
EffectiveOptions = lists:ukeymerge(1,
EffectiveTcpOptions0 = lists:ukeymerge(1,
lists:ukeysort(1, UserOptions),
lists:ukeysort(1, DefOptions)
),
EffectiveTcpOptions = fix_inet_options(EffectiveTcpOptions0),
EffectiveOptions = case Ssl of
true ->
DefSslOptions = application:get_env(lhttpc, ssl_options, []),
UserSslOptions = proplists:get_value(ssl_options, Options, []),
EffectiveSslOpts = lists:ukeymerge(1,
lists:ukeysort(1, UserSslOptions),
lists:ukeysort(1, DefSslOptions)
),
EffectiveTcpOptions ++ EffectiveSslOpts;
false ->
EffectiveTcpOptions
end,

EffectiveTimeout = proplists:get_value(connect_timeout, Options, DefTimeout),
State = #client_state{
host = Host,
Expand Down Expand Up @@ -943,3 +957,18 @@ is_ipv6_host(Host) ->
end
end
end.

%%------------------------------------------------------------------------------
%% @private
%%------------------------------------------------------------------------------
fix_inet_options(Options) ->
lists:filtermap(
fun ({AddressFamily, Bool}) when AddressFamily =:= inet;
AddressFamily =:= inet6;
AddressFamily =:= local ->
case Bool of
true -> {true, AddressFamily};
false -> false
end;
(Option) -> {true, Option}
end, Options).

0 comments on commit 4ac71aa

Please sign in to comment.