diff options
author | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-07-05 08:54:43 -0500 |
---|---|---|
committer | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-07-05 08:54:43 -0500 |
commit | 632f2dd304cc9dbd280711424985684fa8ada365 (patch) | |
tree | ff21bbf3296bb3b20254d557f660205a868a4c38 /src | |
parent | 6fdbea7094c7582635b3c809989497ec9dfaf137 (diff) | |
parent | 9e4bf8a3bad3f46f8094339b38ac880ec1b977d2 (diff) |
Merge pull request #579 from carlosedp/add-proxy
Add proxy support to bootstrap and rebar3. Enhancement #561.
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar3.erl | 13 | ||||
-rw-r--r-- | src/rebar_pkg_resource.erl | 2 | ||||
-rw-r--r-- | src/rebar_prv_update.erl | 3 | ||||
-rw-r--r-- | src/rebar_utils.erl | 19 |
4 files changed, 24 insertions, 13 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl index c501709..a797c46 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -273,13 +273,6 @@ 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, [{profile, rebar}]), + rebar_utils:set_httpc_options(). + diff --git a/src/rebar_pkg_resource.erl b/src/rebar_pkg_resource.erl index 5b37788..450ff1e 100644 --- a/src/rebar_pkg_resource.erl +++ b/src/rebar_pkg_resource.erl @@ -96,7 +96,7 @@ request(Url, ETag) -> case httpc:request(get, {Url, [{"if-none-match", ETag} || ETag =/= false]}, [{relaxed, true}], [{body_format, binary}], - hex) of + rebar) of {ok, {{_Version, 200, _Reason}, Headers, Body}} -> ?DEBUG("Successfully downloaded ~s", [Url]), {"etag", ETag1} = lists:keyfind("etag", 1, Headers), diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 6838bab..64fe65e 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -43,7 +43,8 @@ do(State) -> Url = rebar_state:get(State, rebar_packages_cdn, "https://s3.amazonaws.com/s3.hex.pm/registry.ets.gz"), {ok, _RequestId} = httpc:request(get, {Url, []}, - [], [{stream, TmpFile}, {sync, true}]), + [], [{stream, TmpFile}, {sync, true}], + rebar), {ok, Data} = file:read_file(TmpFile), Unzipped = zlib:gunzip(Data), ok = file:write_file(HexFile, Unzipped), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 0cbc7c2..1cd6694 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,19 @@ maybe_ends_in_comma(H) -> "," ++ Flag -> lists:reverse(Flag); _ -> false end. + +get_http_vars(Scheme) -> + GlobalConfigFile = rebar_dir:global_config(), + Config = rebar_config:consult_file(GlobalConfigFile), + proplists:get_value(Scheme, Config, []). + +set_httpc_options() -> + set_httpc_options(https_proxy, get_http_vars(https_proxy)), + set_httpc_options(proxy, get_http_vars(http_proxy)). + +set_httpc_options(_, []) -> + ok; + +set_httpc_options(Scheme, Proxy) -> + {ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy), + httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar). |