Skip to content

Commit

Permalink
utils/curl: workaround curl bug for --head --request GET
Browse files Browse the repository at this point in the history
The `curl --head --request GET` causes a full download to happen on
`curl` from 8.7.0 to 8.9.1[^1] which causes poor UX due to slow
Cask downloads that can take almost twice as long as they should.

[^1]: #18213
  • Loading branch information
cho-m committed Oct 5, 2024
1 parent 1e29665 commit b509ea9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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/,
Expand Down
12 changes: 10 additions & 2 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ def curl_output(*args, **options)
end

def curl_headers(*args, wanted_headers: [], **options)
[[], ["--request", "GET"]].each do |request_args|
get_retry_args = ["--request", "GET"]
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
Expand Down Expand Up @@ -494,9 +497,14 @@ def curl_http_content_headers_and_checksum(
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
Expand Down

0 comments on commit b509ea9

Please sign in to comment.