From 01eeda6c2c46a83ac2b288c0602cfc320e849a88 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 20 Apr 2018 18:28:03 -0400 Subject: Handle Schemaless Proxy URLs in ENV vars We've had multiple tickets opened because of unclear PROXY settings when the scheme is missing form the URI. To be helpful, we instead add them dynamically whenever they're missing. Example issues: - https://github.com/erlang/rebar3/issues/1747 - https://github.com/erlang/rebar3/issues/1697 --- src/rebar_utils.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 9bbe54e..a911cc2 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -854,10 +854,18 @@ set_httpc_options(_, []) -> ok; 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), 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) -> case http_uri:parse(Url) of {ok, {Scheme, UserInfo, Host, Port, Path, Query}} -> -- cgit v1.1 From 088c47ad1d1f23650dc7bdc3d10659b9a223abb8 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 20 Apr 2018 18:49:44 -0400 Subject: Add proxy auto-scheme test --- test/rebar_utils_SUITE.erl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 8b8769b..e4a5bd3 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -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:", Port = "1234", @@ -291,13 +293,13 @@ proxy_auth(_Config, ProxyEnvKey) -> ?assertEqual([], rebar_utils:get_proxy_auth()), %% 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(), ?assertEqual([{proxy_auth, {"Username", "Password"}}], rebar_utils:get_proxy_auth()), %% 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(), ?assertEqual([{proxy_auth, {"", "?!abc#$"}}], rebar_utils:get_proxy_auth()), -- cgit v1.1