Browse Source

Merge pull request #1756 from ferd/handle-schemeless-proxy

Handle Schema-less Proxy URLs in ENV vars
pull/1757/head
Fred Hebert 7 years ago
committed by GitHub
parent
commit
39b743b36a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions
  1. +9
    -1
      src/rebar_utils.erl
  2. +8
    -6
      test/rebar_utils_SUITE.erl

+ 9
- 1
src/rebar_utils.erl View File

@ -854,10 +854,18 @@ set_httpc_options(_, []) ->
ok; ok;
set_httpc_options(Scheme, Proxy) -> set_httpc_options(Scheme, Proxy) ->
{ok, {_, UserInfo, Host, Port, _, _}} = http_uri:parse(Proxy),
URI = normalise_proxy(Scheme, Proxy),
{ok, {_, UserInfo, Host, Port, _, _}} = http_uri:parse(URI),
httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar), httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar),
set_proxy_auth(UserInfo). set_proxy_auth(UserInfo).
normalise_proxy(Scheme, URI) ->
case re:run(URI, "://", [unicode]) of
nomatch when Scheme =:= https_proxy -> "https://" ++ URI;
nomatch when Scheme =:= proxy -> "http://" ++ URI;
_ -> URI
end.
url_append_path(Url, ExtraPath) -> url_append_path(Url, ExtraPath) ->
case http_uri:parse(Url) of case http_uri:parse(Url) of
{ok, {Scheme, UserInfo, Host, Port, Path, Query}} -> {ok, {Scheme, UserInfo, Host, Port, Path, Query}} ->

+ 8
- 6
test/rebar_utils_SUITE.erl View File

@ -275,11 +275,13 @@ tup_merge(_Config) ->
) )
). ).
proxy_auth(_Config) ->
proxy_auth(_Config, "http_proxy"),
proxy_auth(_Config, "https_proxy").
proxy_auth(Config) ->
proxy_auth(Config, "http://", "http_proxy"),
proxy_auth(Config, "https://", "https_proxy"),
proxy_auth(Config, "", "http_proxy"),
proxy_auth(Config, "", "https_proxy").
proxy_auth(_Config, ProxyEnvKey) ->
proxy_auth(_Config, Schema, ProxyEnvKey) ->
Host = "host:", Host = "host:",
Port = "1234", Port = "1234",
@ -291,13 +293,13 @@ proxy_auth(_Config, ProxyEnvKey) ->
?assertEqual([], rebar_utils:get_proxy_auth()), ?assertEqual([], rebar_utils:get_proxy_auth()),
%% proxy auth with regular username/password %% proxy auth with regular username/password
os:putenv(ProxyEnvKey, "http://Username:Password@" ++ Host ++ Port),
os:putenv(ProxyEnvKey, Schema++"Username:Password@" ++ Host ++ Port),
rebar_utils:set_httpc_options(), rebar_utils:set_httpc_options(),
?assertEqual([{proxy_auth, {"Username", "Password"}}], ?assertEqual([{proxy_auth, {"Username", "Password"}}],
rebar_utils:get_proxy_auth()), rebar_utils:get_proxy_auth()),
%% proxy auth with username missing and url encoded password %% proxy auth with username missing and url encoded password
os:putenv(ProxyEnvKey, "http://:%3F!abc%23%24@" ++ Host ++ Port),
os:putenv(ProxyEnvKey, Schema++":%3F!abc%23%24@" ++ Host ++ Port),
rebar_utils:set_httpc_options(), rebar_utils:set_httpc_options(),
?assertEqual([{proxy_auth, {"", "?!abc#$"}}], ?assertEqual([{proxy_auth, {"", "?!abc#$"}}],
rebar_utils:get_proxy_auth()), rebar_utils:get_proxy_auth()),

Loading…
Cancel
Save