Skip to content

Commit

Permalink
Modify env in Utils::Curl instead of bin/brew
Browse files Browse the repository at this point in the history
  • Loading branch information
clint-stripe committed Aug 10, 2023
1 parent 7b525db commit 6e2f6a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
14 changes: 14 additions & 0 deletions Library/Homebrew/test/utils/curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@
end
end

describe "extra_curl_args" do
it "doesn't set CURL_HOME when HOMEBREW_CURLRC is unset" do
expect(extra_curl_env).not_to include("CURL_HOME")
end

it "sets CURL_HOME when HOMEBREW_CURLRC and HOMEBREW_CURL_HOME are set" do
ENV["HOMEBREW_CURLRC"] = "1"
ENV["HOMEBREW_CURL_HOME"] = "/tmp/curl_home"
expect(extra_curl_env).to include("CURL_HOME" => "/tmp/curl_home")
ensure
ENV["HOMEBREW_CURLRC"] = nil
end
end

describe "url_protected_by_cloudflare?" do
it "returns `true` when a URL is protected by Cloudflare" do
expect(url_protected_by_cloudflare?(details[:cloudflare][:single_cookie])).to be(true)
Expand Down
13 changes: 12 additions & 1 deletion Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def curl_with_workarounds(

result = system_command curl_executable(use_homebrew_curl: use_homebrew_curl),
args: curl_args(*args, **options),
env: env,
env: env.merge(extra_curl_env),
timeout: end_time&.remaining,
**command_options

Expand Down Expand Up @@ -557,6 +557,17 @@ def curl_response_follow_redirections(responses, base_url)

private

# Determines extra environment variables to set based on global configuration
# @return [Hash] A hash containing the environment variables to set for `curl`
def extra_curl_env
env = {}
if Homebrew::EnvConfig.curlrc? && !Homebrew::EnvConfig.curl_home.nil?
env["CURL_HOME"] = Homebrew::EnvConfig.curl_home
end

env
end

# Parses HTTP response text from `curl` output into a hash containing the
# information from the status line (status code and, optionally,
# descriptive text) and headers.
Expand Down
7 changes: 0 additions & 7 deletions bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,6 @@ ENV_VAR_NAMES=(
HOME SHELL PATH TERM TERMINFO TERMINFO_DIRS COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY
)

# When using .curlrc is permitted, also allow setting CURL_HOME
if [[ -n "${HOMEBREW_CURLRC-}" && -n "${HOMEBREW_CURL_HOME-}" ]]
then
FILTERED_ENV+=("CURL_HOME=${HOMEBREW_CURL_HOME}")
fi

# Filter all but the specific variables.
for VAR in "${ENV_VAR_NAMES[@]}" "${!HOMEBREW_@}"
do
Expand Down

0 comments on commit 6e2f6a8

Please sign in to comment.