Packages
launchdarkly_server_sdk
2.1.2
3.11.0
3.10.1
3.9.0
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.0
3.5.0
3.4.0
3.3.1
3.3.0
3.2.0
3.1.0
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.1.2
2.1.1
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.6.0
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.3
1.1.2
1.1.1
retired
1.1.0
retired
1.0.1
retired
1.0.0
retired
1.0.0-beta4
retired
1.0.0-beta3
retired
1.0.0-beta2
retired
LaunchDarkly SDK for Erlang
Current section
Files
Jump to
Current section
Files
src/ldclient_http_options.erl
%%-------------------------------------------------------------------
%% @doc Http option parsing for http and gun.
%% @private
%% @end
%%-------------------------------------------------------------------
-module(ldclient_http_options).
%% API
-export([httpc_parse_http_options/1]).
-export([httpc_parse_http_options/2]).
-export([httpc_append_custom_headers/2]).
-export([gun_parse_http_options/1]).
-export([gun_parse_http_options/2]).
-export([gun_append_custom_headers/2]).
%% Implementation for httpc.
-spec httpc_parse_http_options(Options :: ldclient_config:http_options(), BaseOptions :: list()) -> list().
httpc_parse_http_options(Options, BaseOptions) ->
OptionsWithTls = httpc_parse_tls_options(BaseOptions, Options),
httpc_parse_connect_timeout(OptionsWithTls, Options).
-spec httpc_parse_http_options(Options :: ldclient_config:http_options()) -> list().
httpc_parse_http_options(Options) ->
httpc_parse_http_options(Options, []).
-spec httpc_parse_tls_options(HttpOptions :: list(), ConfigOptions :: ldclient_config:http_options()) -> list().
httpc_parse_tls_options(HttpOptions, #{tls_options := undefined}) -> HttpOptions;
httpc_parse_tls_options(HttpOptions, #{tls_options := TlsOptions}) ->
[{ssl, TlsOptions} | HttpOptions].
-spec httpc_parse_connect_timeout(HttpOptions :: list(), ConfigOptions :: ldclient_config:http_options()) -> list().
httpc_parse_connect_timeout(HttpOptions, #{connect_timeout := undefined}) -> HttpOptions;
httpc_parse_connect_timeout(HttpOptions, #{connect_timeout := TimeoutTime}) ->
[{connect_timeout, TimeoutTime} | HttpOptions].
-spec httpc_append_custom_headers(Headers :: list(), ConfigOptions :: ldclient_config:http_options()) -> list().
httpc_append_custom_headers(Headers, #{custom_headers := undefined}) -> Headers;
httpc_append_custom_headers(Headers, #{custom_headers := CustomHeaders}) -> lists:append(Headers, CustomHeaders).
%% Implementation for gun
-spec gun_parse_http_options(Options :: ldclient_config:http_options()) -> map().
gun_parse_http_options(undefined) ->
#{retry => 0, protocols => [http]};
gun_parse_http_options(HttpOptions) ->
gun_parse_http_options(HttpOptions, #{
retry => 0, protocols => [http]
}).
-spec gun_parse_http_options(Options :: ldclient_config:http_options(), GunOptions :: map()) -> map().
gun_parse_http_options(HttpOptions, GunOptions) ->
OptionsWithTls = gun_parse_tls_options(HttpOptions, GunOptions),
gun_parse_connect_timeout(HttpOptions, OptionsWithTls).
-spec gun_parse_tls_options(ConfigOptions :: ldclient_config:http_options(), GunOptions :: map()) -> map().
gun_parse_tls_options(#{tls_options := undefined}, GunOptions) -> GunOptions;
gun_parse_tls_options(#{tls_options := TlsOptions}, GunOptions) ->
GunOptions#{
transport_opts => TlsOptions
}.
-spec gun_append_custom_headers(Headers :: map(), ConfigOptions :: ldclient_config:http_options()) -> map().
gun_append_custom_headers(Headers, #{custom_headers := undefined}) -> Headers;
gun_append_custom_headers(Headers, #{custom_headers := CustomHeaders}) ->
maps:merge(Headers, maps:from_list(CustomHeaders)).
-spec gun_parse_connect_timeout(ConfigOptions :: ldclient_config:http_options(), GunOptions :: map()) -> map().
gun_parse_connect_timeout(#{connect_timeout := undefined}, GunOptions) -> GunOptions;
gun_parse_connect_timeout(#{connect_timeout := TimeoutTime}, GunOptions) ->
GunOptions#{
connect_timeout => TimeoutTime
}.