Bladeren bron

Get proxy vars from ~/.config/rebar3/rebar.config. Variable format is {http_proxy, http://host:port} or {http_proxy, http://host:port}

pull/579/head
CarlosEDP 10 jaren geleden
bovenliggende
commit
60265aba34
2 gewijzigde bestanden met toevoegingen van 43 en 85 verwijderingen
  1. +22
    -37
      bootstrap
  2. +21
    -48
      src/rebar_utils.erl

+ 22
- 37
bootstrap Bestand weergeven

@ -82,7 +82,7 @@ extract(Binary) ->
{ok, Contents}.
request(Url) ->
setHttpcOptions(),
set_httpc_options(),
case httpc:request(get, {Url, []},
[{relaxed, true}],
[{body_format, binary}]) of
@ -92,45 +92,30 @@ request(Url) ->
Error
end.
setHttpcOptions() ->
%% Get http_proxy and https_proxy environment variables
case os:getenv("http_proxy") of
false ->
Http = "";
Http ->
Http
end,
case os:getenv("https_proxy") of
false ->
Https = "";
Https ->
Https
end,
%% Parse the variables to extract host and port
Opts = [],
case http_uri:parse(Http) of
{ok,{_, [], Host, Port, _, []}} ->
Opts1 = Opts ++ [{proxy, {{Host, Port}, []}}];
{error, _} ->
Opts1 = Opts
end,
case http_uri:parse(Https) of
{ok,{_, [], Host2, Port2, _, []}} ->
Opts2 = Opts1 ++ [{https_proxy, {{Host2, Port2}, []}}];
{error, _} ->
Opts2 = Opts1
end,
case Opts2 of
[] ->
ok;
get_http_var() ->
{ok, [[Home]]} = init:get_argument(home),
ConfDir = filename:join(Home, ".config/rebar3"),
case file:consult(filename:join(ConfDir, "rebar.config")) of
{ok, Config} ->
Config;
_ ->
httpc:set_options(Opts2),
ok
[]
end.
get_http(Scheme) ->
proplists:get_value(Scheme, get_http_var(), "").
set_httpc_options() ->
set_httpc_options(https_proxy, get_http(https_proxy)),
set_httpc_options(proxy, get_http(http_proxy)).
set_httpc_options(_, []) ->
ok;
set_httpc_options(Scheme, Proxy) ->
{ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy),
httpc:set_options([{Scheme, {{Host, Port}, []}}]).
compile(App, FirstFiles) ->
Dir = filename:join(filename:absname("_build/default/lib/"), App),
filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])),

+ 21
- 48
src/rebar_utils.erl Bestand weergeven

@ -663,53 +663,26 @@ maybe_ends_in_comma(H) ->
_ -> false
end.
get_http_var() ->
{ok, [[Home]]} = init:get_argument(home),
ConfDir = filename:join(Home, ".config/rebar3"),
case file:consult(filename:join(ConfDir, "rebar.config")) of
{ok, Config} ->
Config;
_ ->
[]
end.
get_http(Scheme) ->
proplists:get_value(Scheme, get_http_var(), "").
set_httpc_options() ->
%% Get http_proxy and https_proxy environment variables
case os:getenv("http_proxy") of
false ->
Http = "";
Http ->
Http
end,
case os:getenv("https_proxy") of
false ->
Https = "";
Https ->
Https
end,
%% Parse the variables to extract host and port
Opts = [],
case http_uri:parse(Http) of
{ok,{_, [], Host, Port, _, []}} ->
Opts1 = Opts ++ [{proxy, {{Host, Port}, []}}];
{error, _} ->
Opts1 = Opts
end,
set_httpc_options(https_proxy, get_http(https_proxy)),
set_httpc_options(proxy, get_http(http_proxy)).
case http_uri:parse(Https) of
{ok,{_, [], Host2, Port2, _, []}} ->
Opts2 = Opts1 ++ [{https_proxy, {{Host2, Port2}, []}}];
{error, _} ->
Opts2 = Opts1
end,
case Opts2 of
[] ->
Opts3 = [
{max_sessions, 4},
{max_keep_alive_length, 4},
{keep_alive_timeout, 120000},
{max_pipeline_length, 4},
{pipeline_timeout, 60000}
];
_ ->
Opts3 = Opts2 ++ [
{max_sessions, 4},
{max_keep_alive_length, 4},
{keep_alive_timeout, 120000},
{max_pipeline_length, 4},
{pipeline_timeout, 60000}
]
end,
httpc:set_options(Opts3).
set_httpc_options(_, []) ->
ok;
set_httpc_options(Scheme, Proxy) ->
{ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy),
httpc:set_options([{Scheme, {{Host, Port}, []}}]).

Laden…
Annuleren
Opslaan