Rescue ErrorDuringExecution instead of changing curl_headers return type.

This commit is contained in:
Markus Reiter 2023-05-09 07:25:00 +02:00
parent 16f3a05e45
commit e493d0cb04
No known key found for this signature in database
GPG Key ID: 245293B51702655B
2 changed files with 19 additions and 16 deletions

View File

@ -182,6 +182,7 @@ module Homebrew
headers = []
[:default, :browser].each do |user_agent|
begin
parsed_output = curl_headers(
url,
wanted_headers: ["location", "content-disposition"],
@ -189,7 +190,9 @@ module Homebrew
user_agent: user_agent,
**DEFAULT_CURL_OPTIONS,
)
next if parsed_output.blank?
rescue ErrorDuringExecution
next
end
parsed_output[:responses].each { |response| headers << response[:headers] }
break if headers.present?

View File

@ -213,8 +213,7 @@ module Utils
)
# 22 means a non-successful HTTP status code, not a `curl` error, so we still got some headers.
next if !result.success? && result.exit_status != 22
if result.success? || result.exit_status == 22
parsed_output = parse_curl_output(result.stdout)
# If we didn't get any wanted header yet, retry using `GET`.
@ -224,7 +223,8 @@ module Utils
return parsed_output if result.success?
end
nil
result.assert_success!
end
end
# Check if a URL is protected by CloudFlare (e.g. badlion.net and jaxx.io).