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,14 +182,17 @@ module Homebrew
headers = [] headers = []
[:default, :browser].each do |user_agent| [:default, :browser].each do |user_agent|
parsed_output = curl_headers( begin
url, parsed_output = curl_headers(
wanted_headers: ["location", "content-disposition"], url,
use_homebrew_curl: homebrew_curl, wanted_headers: ["location", "content-disposition"],
user_agent: user_agent, use_homebrew_curl: homebrew_curl,
**DEFAULT_CURL_OPTIONS, user_agent: user_agent,
) **DEFAULT_CURL_OPTIONS,
next if parsed_output.blank? )
rescue ErrorDuringExecution
next
end
parsed_output[:responses].each { |response| headers << response[:headers] } parsed_output[:responses].each { |response| headers << response[:headers] }
break if headers.present? break if headers.present?

View File

@ -213,18 +213,18 @@ module Utils
) )
# 22 means a non-successful HTTP status code, not a `curl` error, so we still got some headers. # 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)
parsed_output = parse_curl_output(result.stdout) # If we didn't get any wanted header yet, retry using `GET`.
next if request_args.empty? && wanted_headers.any? &&
parsed_output.fetch(:responses).none? { |r| (r.fetch(:headers).keys & wanted_headers).any? }
# If we didn't get any wanted header yet, retry using `GET`. return parsed_output if result.success?
next if request_args.empty? && wanted_headers.any? && end
parsed_output.fetch(:responses).none? { |r| (r.fetch(:headers).keys & wanted_headers).any? }
return parsed_output if result.success? result.assert_success!
end end
nil
end end
# Check if a URL is protected by CloudFlare (e.g. badlion.net and jaxx.io). # Check if a URL is protected by CloudFlare (e.g. badlion.net and jaxx.io).