diff --git a/lib/elixir_make/downloader/httpc.ex b/lib/elixir_make/downloader/httpc.ex index f53026a..0bb6aaa 100644 --- a/lib/elixir_make/downloader/httpc.ex +++ b/lib/elixir_make/downloader/httpc.ex @@ -13,14 +13,14 @@ defmodule ElixirMake.Downloader.Httpc do {:ok, _} = Application.ensure_all_started(:public_key) if proxy = proxy_env(:http) do - Mix.shell().info("Using HTTP_PROXY: #{proxy}") + Mix.shell().info("Using HTTP_PROXY: #{without_userinfo(proxy)}") %{host: host, port: port} = URI.parse(proxy) :httpc.set_options([{:proxy, {{String.to_charlist(host), port}, []}}]) end if proxy = proxy_env(:https) do - Mix.shell().info("Using HTTPS_PROXY: #{proxy}") + Mix.shell().info("Using HTTPS_PROXY: #{without_userinfo(proxy)}") %{host: host, port: port} = URI.parse(proxy) :httpc.set_options([{:https_proxy, {{String.to_charlist(host), port}, []}}]) end @@ -39,7 +39,7 @@ defmodule ElixirMake.Downloader.Httpc do options = [body_format: :binary, max_header_size: 65_536] - case :httpc.request(:get, {url_charlist, []}, https_options, options) do + case :httpc.request(:get, {url_charlist, []}, https_options ++ proxy_auth(url), options) do {:ok, {{_, 200, _}, _headers, body}} -> {:ok, body} @@ -48,6 +48,33 @@ defmodule ElixirMake.Downloader.Httpc do end end + # httpc doesn't read credentials from the proxy URL, so pass them as + # proxy_auth, as Mix.Utils.proxy_config/1 does. + defp proxy_auth(url) do + proxy = + case URI.parse(url) do + %URI{scheme: "https"} -> proxy_env(:https) + _ -> proxy_env(:http) + end + + case proxy && URI.parse(proxy) do + %URI{userinfo: userinfo} when is_binary(userinfo) -> + destructure [user, pass], String.split(userinfo, ":", parts: 2) + [proxy_auth: {String.to_charlist(user), String.to_charlist(pass || "")}] + + _ -> + [] + end + end + + # Keeps proxy credentials out of build logs. + defp without_userinfo(proxy) do + case URI.parse(proxy) do + %URI{userinfo: nil} -> proxy + uri -> URI.to_string(%{uri | userinfo: nil}) + end + end + defp cacerts_options do cond do path = System.get_env("HEX_CACERTS_PATH") ->