Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/steps/fetch/fetch_musl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ 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 =
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])

_ ->
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!"
Expand Down
12 changes: 11 additions & 1 deletion lib/util/default_erts_resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ 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 =
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])

_ ->
Req.get!(url, raw: true)
end
Comment thread
feng19 marked this conversation as resolved.

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!"
Expand Down
20 changes: 20 additions & 0 deletions lib/util/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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