Merge pull request #18508 from Homebrew/curl-skip-get

utils/curl: workaround curl bug for `--head --request GET`
This commit is contained in:
Michael Cho 2024-10-08 08:44:05 -04:00 committed by GitHub
commit a3d8f4e0e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -27,6 +27,8 @@ RSpec.describe CurlGitHubPackagesDownloadStrategy do
before do
stub_const("HOMEBREW_GITHUB_PACKAGES_AUTH", authorization) if authorization.present?
allow(strategy).to receive(:curl_version).and_return(Version.new("8.7.1"))
allow(strategy).to receive(:system_command)
.with(
/curl/,

View File

@ -18,6 +18,8 @@ RSpec.describe CurlPostDownloadStrategy do
describe "#fetch" do
before do
allow(strategy).to receive(:curl_version).and_return(Version.new("8.6.0"))
allow(strategy).to receive(:system_command)
.with(
/curl/,

View File

@ -234,7 +234,11 @@ module Utils
end
def curl_headers(*args, wanted_headers: [], **options)
[[], ["--request", "GET"]].each do |request_args|
get_retry_args = ["--request", "GET"]
# This is a workaround for https://github.com/Homebrew/brew/issues/18213
get_retry_args << "--http1.1" if curl_version >= Version.new("8.7") && curl_version < Version.new("8.10")
[[], get_retry_args].each do |request_args|
result = curl_output(
"--fail", "--location", "--silent", "--head", *request_args, *args,
**options
@ -494,9 +498,14 @@ module Utils
T.must(file).unlink
end
def curl_version
@curl_version ||= {}
@curl_version[curl_path] ||= Version.new(curl_output("-V").stdout[/curl (\d+(\.\d+)+)/, 1])
end
def curl_supports_fail_with_body?
@curl_supports_fail_with_body ||= Hash.new do |h, key|
h[key] = Version.new(curl_output("-V").stdout[/curl (\d+(\.\d+)+)/, 1]) >= Version.new("7.76.0")
h[key] = curl_version >= Version.new("7.76.0")
end
@curl_supports_fail_with_body[curl_path]
end