From 44bef9b609c29e244cc9ac2e53d1c5c45d1822ec Mon Sep 17 00:00:00 2001 From: motobob Date: Mon, 15 Oct 2018 11:46:54 +0100 Subject: [PATCH 1/2] allow master defaults in connect --- src/lhttpc_client.erl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lhttpc_client.erl b/src/lhttpc_client.erl index d32406f5..73da6758 100644 --- a/src/lhttpc_client.erl +++ b/src/lhttpc_client.erl @@ -150,6 +150,9 @@ execute(From, Host, Port, Ssl, Path, Method, Hdrs0, Body, Options) -> %% Get a socket for the pool or exit %Socket = lhttpc_manager:ensure_call(Pool, SocketRequest, Options), Socket = lhttpc_manager:ensure_call(Pool, self(), Host, Port, Ssl, Options), + % get the socket connect settings from client or use defaults + DefConOptions = application:get_env(lhttpc, connect_options, []), + DefConTimeout = proplists:get_value(DefConOptions, connect_timeout, infinity), State = #client_state{ host = Host, port = Port, @@ -159,9 +162,8 @@ execute(From, Host, Port, Ssl, Path, Method, Hdrs0, Body, Options) -> requester = From, request_headers = Hdrs, socket = Socket, - connect_timeout = proplists:get_value(connect_timeout, Options, - infinity), - connect_options = proplists:get_value(connect_options, Options, []), + connect_timeout = proplists:get_value(connect_timeout, Options, DefConTimeout), + connect_options = proplists:get_value(connect_options, Options, DefConOptions), attempts = 1 + proplists:get_value(send_retry, Options, 1), partial_upload = PartialUpload, upload_window = UploadWindowSize, From b12602c5110578ea277ff8af220923360793f365 Mon Sep 17 00:00:00 2001 From: motobob Date: Mon, 15 Oct 2018 13:58:58 +0100 Subject: [PATCH 2/2] handkle all permutations --- src/lhttpc_client.erl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lhttpc_client.erl b/src/lhttpc_client.erl index 73da6758..7f4bb645 100644 --- a/src/lhttpc_client.erl +++ b/src/lhttpc_client.erl @@ -151,8 +151,15 @@ execute(From, Host, Port, Ssl, Path, Method, Hdrs0, Body, Options) -> %Socket = lhttpc_manager:ensure_call(Pool, SocketRequest, Options), Socket = lhttpc_manager:ensure_call(Pool, self(), Host, Port, Ssl, Options), % get the socket connect settings from client or use defaults - DefConOptions = application:get_env(lhttpc, connect_options, []), - DefConTimeout = proplists:get_value(DefConOptions, connect_timeout, infinity), + % unfold all atoms and allow users to overwrite a single param only + 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, + lists:ukeysort(1, UserOptions), + lists:ukeysort(1, DefOptions) + ), + EffectiveTimeout = proplists:get_value(connect_timeout, Options, DefTimeout), State = #client_state{ host = Host, port = Port, @@ -162,8 +169,8 @@ execute(From, Host, Port, Ssl, Path, Method, Hdrs0, Body, Options) -> requester = From, request_headers = Hdrs, socket = Socket, - connect_timeout = proplists:get_value(connect_timeout, Options, DefConTimeout), - connect_options = proplists:get_value(connect_options, Options, DefConOptions), + connect_timeout = EffectiveTimeout, + connect_options = EffectiveOptions, attempts = 1 + proplists:get_value(send_retry, Options, 1), partial_upload = PartialUpload, upload_window = UploadWindowSize,