Skip to content

Commit

Permalink
download_strategy: skip GET retry for headers
Browse files Browse the repository at this point in the history
The `curl --head --request GET` causes a full download to happen on
`curl` prior to 8.10.0[^1] (ignoring `curl` 8.6.0 which returned a
"Weird server reply" due to a bug[^2]) which causes poor UX due to slow
Cask downloads that can take almost twice as long as it should.

[^1]: #18213
[^2]: https://curl.se/mail/lib-2024-02/0000.html
  • Loading branch information
cho-m committed Oct 5, 2024
1 parent 1e29665 commit a0fd8dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def resolve_url_basename_time_file_size(url, timeout: nil)
return @resolved_info_cache[url] if @resolved_info_cache.include?(url)

begin
parsed_output = curl_headers(url.to_s, wanted_headers: ["content-disposition"], timeout:)
parsed_output = curl_headers(url.to_s, wanted_headers: ["content-disposition"], skip_get_retry: true, timeout:)
rescue ErrorDuringExecution
return [url, parse_basename(url), nil, nil, false]
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def curl_output(*args, **options)
curl_with_workarounds(*args, print_stderr: false, show_output: true, **options)
end

def curl_headers(*args, wanted_headers: [], **options)
def curl_headers(*args, wanted_headers: [], skip_get_retry: false, **options)
[[], ["--request", "GET"]].each do |request_args|
result = curl_output(
"--fail", "--location", "--silent", "--head", *request_args, *args,
Expand All @@ -249,7 +249,7 @@ def curl_headers(*args, wanted_headers: [], **options)
].include?(result.exit_status)
parsed_output = parse_curl_output(result.stdout)

if request_args.empty?
if request_args.empty? && !skip_get_retry
# If we didn't get any wanted header yet, retry using `GET`.
next if wanted_headers.any? &&
parsed_output.fetch(:responses).none? { |r| (r.fetch(:headers).keys & wanted_headers).any? }
Expand Down

0 comments on commit a0fd8dc

Please sign in to comment.