From bb76bd4cc4bb63068de98be410fc318451f1afc1 Mon Sep 17 00:00:00 2001 From: Kevin Pan Date: Fri, 14 Nov 2025 10:16:08 +0800 Subject: [PATCH 1/2] feat: support proxy for download fetch --- lib/steps/fetch/fetch_musl.ex | 23 ++++++++++++++++++++++- lib/util/default_erts_resolver.ex | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/steps/fetch/fetch_musl.ex b/lib/steps/fetch/fetch_musl.ex index 27657fb..3fd71ff 100644 --- a/lib/steps/fetch/fetch_musl.ex +++ b/lib/steps/fetch/fetch_musl.ex @@ -53,7 +53,28 @@ defmodule Burrito.Steps.Fetch.FetchMusl do defp do_download(url, cache_key) do {:ok, _} = Application.ensure_all_started(:req) Log.info(:step, "Downloading file: #{url}") - resp = Req.get!(url, raw: true) + + resp = + cond do + proxy = System.get_env("HTTP_PROXY") || System.get_env("http_proxy") -> + Log.info(:step, "Using HTTP_PROXY: #{proxy}") + URI.parse(proxy) + + proxy = System.get_env("HTTPS_PROXY") || System.get_env("https_proxy") -> + Log.info(:step, "Using HTTPS_PROXY: #{proxy}") + URI.parse(proxy) + + true -> + nil + end + |> case do + %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + proxy = {String.to_atom(scheme), host, port, []} + Req.get!(url, raw: true, connect_options: [proxy: proxy]) + + _ -> + Req.get!(url, raw: true) + end if resp.status != 200 do raise "Failed to fetch musl runtime: #{url}! (Got #{resp.status}) -- please file an issue! Thanks!" diff --git a/lib/util/default_erts_resolver.ex b/lib/util/default_erts_resolver.ex index 660c129..fed119a 100644 --- a/lib/util/default_erts_resolver.ex +++ b/lib/util/default_erts_resolver.ex @@ -98,7 +98,28 @@ defmodule Burrito.Util.DefaultERTSResolver do defp do_download(url, cache_key) do {:ok, _} = Application.ensure_all_started(:req) Log.info(:step, "Downloading file: #{url}") - resp = Req.get!(url, raw: true) + + resp = + cond do + proxy = System.get_env("HTTP_PROXY") || System.get_env("http_proxy") -> + Log.info(:step, "Using HTTP_PROXY: #{proxy}") + URI.parse(proxy) + + proxy = System.get_env("HTTPS_PROXY") || System.get_env("https_proxy") -> + Log.info(:step, "Using HTTPS_PROXY: #{proxy}") + URI.parse(proxy) + + true -> + nil + end + |> case do + %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + proxy = {String.to_atom(scheme), host, port, []} + Req.get!(url, raw: true, connect_options: [proxy: proxy]) + + _ -> + Req.get!(url, raw: true) + end if resp.status != 200 do raise "Failed to fetch #{url}! (Got #{resp.status}) Perhaps we haven't built a pre-compiled Erlang for this release yet? If this was a 404, please file an issue! Thanks!" From 5241c36abcc2a61f5b1ba8e8990a50aff31e6677 Mon Sep 17 00:00:00 2001 From: Kevin Pan Date: Tue, 6 Jan 2026 09:30:37 +0800 Subject: [PATCH 2/2] feat: move duplicate code to util module --- lib/steps/fetch/fetch_musl.ex | 17 +++-------------- lib/util/default_erts_resolver.ex | 17 +++-------------- lib/util/util.ex | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/steps/fetch/fetch_musl.ex b/lib/steps/fetch/fetch_musl.ex index 3fd71ff..5f6fc60 100644 --- a/lib/steps/fetch/fetch_musl.ex +++ b/lib/steps/fetch/fetch_musl.ex @@ -55,20 +55,9 @@ defmodule Burrito.Steps.Fetch.FetchMusl do Log.info(:step, "Downloading file: #{url}") resp = - cond do - proxy = System.get_env("HTTP_PROXY") || System.get_env("http_proxy") -> - Log.info(:step, "Using HTTP_PROXY: #{proxy}") - URI.parse(proxy) - - proxy = System.get_env("HTTPS_PROXY") || System.get_env("https_proxy") -> - Log.info(:step, "Using HTTPS_PROXY: #{proxy}") - URI.parse(proxy) - - true -> - nil - end - |> case do - %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + case Burrito.Util.get_proxy() do + proxy = %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + Log.info(:step, "Using PROXY: #{proxy}") proxy = {String.to_atom(scheme), host, port, []} Req.get!(url, raw: true, connect_options: [proxy: proxy]) diff --git a/lib/util/default_erts_resolver.ex b/lib/util/default_erts_resolver.ex index fed119a..8185c99 100644 --- a/lib/util/default_erts_resolver.ex +++ b/lib/util/default_erts_resolver.ex @@ -100,20 +100,9 @@ defmodule Burrito.Util.DefaultERTSResolver do Log.info(:step, "Downloading file: #{url}") resp = - cond do - proxy = System.get_env("HTTP_PROXY") || System.get_env("http_proxy") -> - Log.info(:step, "Using HTTP_PROXY: #{proxy}") - URI.parse(proxy) - - proxy = System.get_env("HTTPS_PROXY") || System.get_env("https_proxy") -> - Log.info(:step, "Using HTTPS_PROXY: #{proxy}") - URI.parse(proxy) - - true -> - nil - end - |> case do - %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + case Burrito.Util.get_proxy() do + proxy = %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + Log.info(:step, "Using PROXY: #{proxy}") proxy = {String.to_atom(scheme), host, port, []} Req.get!(url, raw: true, connect_options: [proxy: proxy]) diff --git a/lib/util/util.ex b/lib/util/util.ex index 417ca6b..8e19b85 100644 --- a/lib/util/util.ex +++ b/lib/util/util.ex @@ -47,4 +47,24 @@ defmodule Burrito.Util do def running_standalone?() do System.get_env("__BURRITO") != nil end + + @doc """ + Gets the HTTP or HTTPS proxy from environment variables, if set. + 1. Checks `HTTP_PROXY` and `http_proxy` + 2. Checks `HTTPS_PROXY` and `https_proxy` + 3. Returns `nil` if no proxy is set + """ + @spec get_proxy :: URI.t() | nil + def get_proxy do + cond do + proxy = System.get_env("HTTP_PROXY") || System.get_env("http_proxy") -> + URI.parse(proxy) + + proxy = System.get_env("HTTPS_PROXY") || System.get_env("https_proxy") -> + URI.parse(proxy) + + true -> + nil + end + end end