Skip to content

Commit

Permalink
Merge pull request #2231 from max-au/max-au/ipv6_support_for_proxy
Browse files Browse the repository at this point in the history
rebar3: ipv6 support for proxy
  • Loading branch information
ferd authored Mar 11, 2020
2 parents be7ad3c + 7dd7caa commit 03f721b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,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"])),
Expand Down
16 changes: 16 additions & 0 deletions src/rebar_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,24 @@ set_httpc_options(Scheme, Proxy) ->
Port = maps:get(port, Parts, []),
UserInfo = maps:get(userinfo, Parts, []),
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;
Expand Down

0 comments on commit 03f721b

Please sign in to comment.