diff --git a/bootstrap b/bootstrap index e430e3493..64c088dbb 100755 --- a/bootstrap +++ b/bootstrap @@ -152,8 +152,24 @@ set_httpc_options(_, []) -> set_httpc_options(Scheme, Proxy) -> {ok, {_, UserInfo, Host, Port, _, _}} = http_uri:parse(Proxy), httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar), + proxy_ipfamily(Host, inet:gethostbyname(Host)), set_proxy_auth(UserInfo). +proxy_ipfamily(_Host, {ok, _}) -> + ok; +proxy_ipfamily(Host, {error, nxdomain}) -> + maybe_proxy_family(Host, inet_db:res_option(inet6)). + +maybe_proxy_family(Host, true) -> + maybe_set_ipfamily(inet:gethostbyname(Host, inet), inet); +maybe_proxy_family(Host, false) -> + maybe_set_ipfamily(inet:gethostbyname(Host, inet6), inet6). + +maybe_set_ipfamily({ok, _}, Family) -> + httpc:set_options([{ipfamily, Family}], rebar); +maybe_set_ipfamily(_, _Family) -> + ok. + compile(App, FirstFiles) -> Dir = filename:join(filename:absname("_build/default/lib/"), App), filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index c587363d3..626473f53 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -926,8 +926,24 @@ set_httpc_options(Scheme, Proxy) -> URI = normalise_proxy(Scheme, Proxy), {ok, {_, UserInfo, Host, Port, _, _}} = http_uri:parse(URI), httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar), + proxy_ipfamily(Host, inet:gethostbyname(Host)), set_proxy_auth(UserInfo). +proxy_ipfamily(_Host, {ok, _}) -> + ok; +proxy_ipfamily(Host, {error, nxdomain}) -> + maybe_proxy_family(Host, inet_db:res_option(inet6)). + +maybe_proxy_family(Host, true) -> + maybe_set_ipfamily(inet:gethostbyname(Host, inet), inet); +maybe_proxy_family(Host, false) -> + maybe_set_ipfamily(inet:gethostbyname(Host, inet6), inet6). + +maybe_set_ipfamily({ok, _}, Family) -> + httpc:set_options([{ipfamily, Family}], rebar); +maybe_set_ipfamily(_, _Family) -> + ok. + normalise_proxy(Scheme, URI) -> case re:run(URI, "://", [unicode]) of nomatch when Scheme =:= https_proxy -> "https://" ++ URI;