summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbootstrap2
-rw-r--r--src/rebar3.erl12
-rw-r--r--src/rebar_utils.erl54
3 files changed, 55 insertions, 13 deletions
diff --git a/bootstrap b/bootstrap
index ca40489..1e56263 100755
--- a/bootstrap
+++ b/bootstrap
@@ -123,8 +123,6 @@ setHttpcOptions() ->
Opts2 = Opts1
end,
- io:format("Opts: ~p~n", [Opts2]),
-
case Opts2 of
[] ->
ok;
diff --git a/src/rebar3.erl b/src/rebar3.erl
index c501709..13f6017 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -273,13 +273,5 @@ start_and_load_apps() ->
application:start(public_key),
application:start(ssl),
inets:start(),
- inets:start(httpc, [{profile, hex}]),
- http_opts().
-
-http_opts() ->
- Opts = [{max_sessions, 4},
- {max_keep_alive_length, 4},
- {keep_alive_timeout, 120000},
- {max_pipeline_length, 4},
- {pipeline_timeout, 60000}],
- httpc:set_options(Opts, hex).
+ inets:start(httpc),
+ rebar_utils:set_httpc_options().
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 0cbc7c2..35964ea 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -56,7 +56,8 @@
wordsize/0,
tup_umerge/2,
tup_sort/1,
- line_count/1]).
+ line_count/1,
+ set_httpc_options/0]).
%% for internal use only
-export([otp_release/0]).
@@ -661,3 +662,54 @@ maybe_ends_in_comma(H) ->
"," ++ Flag -> lists:reverse(Flag);
_ -> false
end.
+
+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,
+
+ 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).