From 9906fdc25e3769d07b0de78a18501c7a681e6dc9 Mon Sep 17 00:00:00 2001 From: CarlosEDP Date: Wed, 1 Jul 2015 13:58:40 -0300 Subject: Added support to http and https proxies on bootstrap. Variables are read from environment vars http_proxy and https_proxy. --- bootstrap | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bootstrap b/bootstrap index 41d9725..ca40489 100755 --- a/bootstrap +++ b/bootstrap @@ -82,6 +82,7 @@ extract(Binary) -> {ok, Contents}. request(Url) -> + setHttpcOptions(), case httpc:request(get, {Url, []}, [{relaxed, true}], [{body_format, binary}]) of @@ -91,6 +92,47 @@ 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, + + io:format("Opts: ~p~n", [Opts2]), + + case Opts2 of + [] -> + ok; + _ -> + httpc:set_options(Opts2), + ok + end. + compile(App, FirstFiles) -> Dir = filename:join(filename:absname("_build/default/lib/"), App), filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), -- cgit v1.1