packaging for obs.osmocom.org, based on https://salsa.debian.org/erlang-team/packages/rebar3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
rebar3/src/rebar_httpc_adapter.erl

41 lines
1.5 KiB

%% Derived from hex_core v0.7.1 for extra flexibility.
-module(rebar_httpc_adapter).
-behaviour(r3_hex_http).
-export([request/5]).
%%====================================================================
%% API functions
%%====================================================================
request(Method, URI, ReqHeaders, Body, AdapterConfig) ->
Profile = maps:get(profile, AdapterConfig, default),
Request = build_request(URI, ReqHeaders, Body),
SSLOpts = [{ssl, rebar_utils:ssl_opts(URI)}],
case httpc:request(Method, Request, SSLOpts, [{body_format, binary}], Profile) of
{ok, {{_, StatusCode, _}, RespHeaders, RespBody}} ->
RespHeaders2 = load_headers(RespHeaders),
{ok, {StatusCode, RespHeaders2, RespBody}};
{error, Reason} -> {error, Reason}
end.
%%====================================================================
%% Internal functions
%%====================================================================
build_request(URI, ReqHeaders, Body) ->
build_request2(binary_to_list(URI), dump_headers(ReqHeaders), Body).
build_request2(URI, ReqHeaders, undefined) ->
{URI, ReqHeaders};
build_request2(URI, ReqHeaders, {ContentType, Body}) ->
{URI, ReqHeaders, ContentType, Body}.
dump_headers(Map) ->
maps:fold(fun(K, V, Acc) ->
[{binary_to_list(K), binary_to_list(V)} | Acc] end, [], Map).
load_headers(List) ->
lists:foldl(fun({K, V}, Acc) ->
maps:put(list_to_binary(K), list_to_binary(V), Acc) end, #{}, List).