summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar3.erl3
-rw-r--r--src/rebar_pkg_resource.erl4
-rw-r--r--src/rebar_utils.erl24
3 files changed, 26 insertions, 5 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 4e7e284..1059904 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -145,6 +145,8 @@ run_aux(State, RawArgs) ->
rebar_core:init_command(rebar_state:command_args(State10, Args), Task).
init_config() ->
+ rebar_utils:set_httpc_options(),
+
%% Initialize logging system
Verbosity = log_level(),
ok = rebar_log:init(command_line, Verbosity),
@@ -320,7 +322,6 @@ ensure_running(App, Caller) ->
end.
state_from_global_config(Config, GlobalConfigFile) ->
- rebar_utils:set_httpc_options(),
GlobalConfigTerms = rebar_config:consult_file(GlobalConfigFile),
GlobalConfig = rebar_state:new(GlobalConfigTerms),
diff --git a/src/rebar_pkg_resource.erl b/src/rebar_pkg_resource.erl
index 5817817..8e1713d 100644
--- a/src/rebar_pkg_resource.erl
+++ b/src/rebar_pkg_resource.erl
@@ -107,8 +107,10 @@ make_vsn(_) ->
{error, "Replacing version of type pkg not supported."}.
request(Url, ETag) ->
+ HttpOptions = [{ssl, ssl_opts(Url)}, {relaxed, true} | rebar_utils:get_proxy_auth()],
+
case httpc:request(get, {Url, [{"if-none-match", ETag} || ETag =/= false]++[{"User-Agent", rebar_utils:user_agent()}]},
- [{ssl, ssl_opts(Url)}, {relaxed, true}],
+ HttpOptions,
[{body_format, binary}],
rebar) of
{ok, {{_Version, 200, _Reason}, Headers, Body}} ->
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index f55f40f..a0a44d1 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -70,7 +70,9 @@
info_useless/2,
list_dir/1,
user_agent/0,
- reread_config/1]).
+ reread_config/1,
+ get_proxy_auth/0]).
+
%% for internal use only
-export([otp_release/0]).
@@ -825,8 +827,9 @@ set_httpc_options(_, []) ->
ok;
set_httpc_options(Scheme, Proxy) ->
- {ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy),
- httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar).
+ {ok, {_, UserInfo, Host, Port, _, _}} = http_uri:parse(Proxy),
+ httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar),
+ set_proxy_auth(UserInfo).
url_append_path(Url, ExtraPath) ->
case http_uri:parse(Url) of
@@ -865,3 +868,18 @@ list_dir(Dir) ->
true -> file:list_dir_all(Dir);
false -> file:list_dir(Dir)
end.
+
+set_proxy_auth([]) ->
+ ok;
+set_proxy_auth(UserInfo) ->
+ Idx = string:chr(UserInfo, $:),
+ Username = string:sub_string(UserInfo, 1, Idx-1),
+ Password = string:sub_string(UserInfo, Idx+1),
+ %% password may contain url encoded characters, need to decode them first
+ application:set_env(rebar, proxy_auth, [{proxy_auth, {Username, http_uri:decode(Password)}}]).
+
+get_proxy_auth() ->
+ case application:get_env(rebar, proxy_auth) of
+ undefined -> [];
+ {ok, ProxyAuth} -> ProxyAuth
+ end.