Skip to content

Commit

Permalink
Allow HOMEBREW_CURLRC to provide a path for curl --config
Browse files Browse the repository at this point in the history
  • Loading branch information
clint-stripe committed Aug 14, 2023
1 parent 237d1e7 commit a95f690
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
7 changes: 4 additions & 3 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ module EnvConfig
boolean: true,
},
HOMEBREW_CURLRC: {
description: "If set, do not pass `--disable` when invoking `curl`(1), which disables the " \
"use of `curlrc`.",
boolean: true,
description: "If set to a full path (i.e. beginning with `/`), pass it with `--config` when invoking " \
"`curl`(1). " \
"If set but _not_ a valid path, do not pass `--disable`, which disables the " \
"use of `.curlrc`.",
},
HOMEBREW_DEBUG: {
description: "If set, always assume `--debug` when running commands.",
Expand Down
13 changes: 8 additions & 5 deletions Library/Homebrew/env_config.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ module Homebrew::EnvConfig
sig { returns(T::Boolean) }
def self.curl_verbose?; end

sig { returns(T::Boolean) }
def self.curlrc?; end
sig { returns(T.nilable(String)) }
def self.curlrc; end

sig { returns(T::Boolean) }
def self.debug?; end
Expand Down Expand Up @@ -190,12 +190,12 @@ module Homebrew::EnvConfig
sig { returns(T::Boolean) }
def self.no_installed_dependents_check?; end

sig { returns(T::Boolean) }
def self.no_update_report_new?; end

sig { returns(T.nilable(String)) }
def self.no_proxy; end

sig { returns(T::Boolean) }
def self.no_update_report_new?; end

sig { returns(T.nilable(String)) }
def self.pip_index_url; end

Expand All @@ -220,6 +220,9 @@ module Homebrew::EnvConfig
sig { returns(T.nilable(String)) }
def self.svn; end

sig { returns(T::Boolean) }
def self.system_env_takes_priority?; end

sig { returns(String) }
def self.temp; end

Expand Down
18 changes: 17 additions & 1 deletion Library/Homebrew/test/utils/curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,27 @@
expect(curl_args(*args).first).to eq("--disable")
end

it "doesn't return `--disable` as the first argument when HOMEBREW_CURLRC is set" do
it "doesn't return `--disable` as the first argument when HOMEBREW_CURLRC is set but not a path" do
ENV["HOMEBREW_CURLRC"] = "1"
expect(curl_args(*args).first).not_to eq("--disable")
end

it "doesn't return `--config` when HOMEBREW_CURLRC is unset" do
expect(curl_args(*args)).not_to include(a_string_starting_with("--config"))
end

it "returns `--config` when HOMEBREW_CURLRC is a valid path" do
Tempfile.create do |tmpfile|
path = tmpfile.path
ENV["HOMEBREW_CURLRC"] = path
# We still expect --disable
expect(curl_args(*args).first).to eq("--disable")
expect(curl_args(*args).join(" ")).to include("--config #{path}")
end
ensure
ENV["HOMEBREW_CURLRC"] = nil
end

it "uses `--connect-timeout` when `:connect_timeout` is Numeric" do
expect(curl_args(*args, connect_timeout: 123).join(" ")).to include("--connect-timeout 123")
expect(curl_args(*args, connect_timeout: 123.4).join(" ")).to include("--connect-timeout 123.4")
Expand Down
11 changes: 10 additions & 1 deletion Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ def curl_args(
args = []

# do not load .curlrc unless requested (must be the first argument)
args << "--disable" unless Homebrew::EnvConfig.curlrc?
curlrc = Homebrew::EnvConfig.curlrc
if curlrc&.start_with?("/")
# If the file exists, we still want to disable loading the default curlrc.
args << "--disable" << "--config" << curlrc
elsif curlrc
# This matches legacy behavior: `HOMEBREW_CURLRC` was a bool,
# omitting `--disable` when present.
else
args << "--disable"
end

# echo any cookies received on a redirect
args << "--cookie" << "/dev/null"
Expand Down
2 changes: 1 addition & 1 deletion docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ prefix-specific files take precedence over system-wide files (unless
<br>If set, pass `--verbose` when invoking `curl`(1).

- `HOMEBREW_CURLRC`
<br>If set, do not pass `--disable` when invoking `curl`(1), which disables the use of `curlrc`.
<br>If set to a full path (i.e. beginning with `/`), pass it with `--config` when invoking `curl`(1). If set but _not_ a valid path, do not pass `--disable`, which disables the use of `.curlrc`.

- `HOMEBREW_DEBUG`
<br>If set, always assume `--debug` when running commands.
Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -3137,7 +3137,7 @@ If set, pass \fB\-\-verbose\fR when invoking \fBcurl\fR(1)\.
\fBHOMEBREW_CURLRC\fR
.
.br
If set, do not pass \fB\-\-disable\fR when invoking \fBcurl\fR(1), which disables the use of \fBcurlrc\fR\.
If set to a full path (i\.e\. beginning with \fB/\fR), pass it with \fB\-\-config\fR when invoking \fBcurl\fR(1)\. If set but \fInot\fR a valid path, do not pass \fB\-\-disable\fR, which disables the use of \fB\.curlrc\fR\.
.
.TP
\fBHOMEBREW_DEBUG\fR
Expand Down

0 comments on commit a95f690

Please sign in to comment.