From e493d0cb04acea102ab84126ec5be6e5b924aef8 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 9 May 2023 07:25:00 +0200 Subject: [PATCH] Rescue `ErrorDuringExecution` instead of changing `curl_headers` return type. --- Library/Homebrew/livecheck/strategy.rb | 19 +++++++++++-------- Library/Homebrew/utils/curl.rb | 16 ++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy.rb b/Library/Homebrew/livecheck/strategy.rb index d269cefdd9..abe14e200f 100644 --- a/Library/Homebrew/livecheck/strategy.rb +++ b/Library/Homebrew/livecheck/strategy.rb @@ -182,14 +182,17 @@ module Homebrew headers = [] [:default, :browser].each do |user_agent| - parsed_output = curl_headers( - url, - wanted_headers: ["location", "content-disposition"], - use_homebrew_curl: homebrew_curl, - user_agent: user_agent, - **DEFAULT_CURL_OPTIONS, - ) - next if parsed_output.blank? + begin + parsed_output = curl_headers( + url, + wanted_headers: ["location", "content-disposition"], + use_homebrew_curl: homebrew_curl, + user_agent: user_agent, + **DEFAULT_CURL_OPTIONS, + ) + rescue ErrorDuringExecution + next + end parsed_output[:responses].each { |response| headers << response[:headers] } break if headers.present? diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 963f4e650c..4b2d3b227f 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -213,18 +213,18 @@ 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) - 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`. - next if request_args.empty? && wanted_headers.any? && - parsed_output.fetch(:responses).none? { |r| (r.fetch(:headers).keys & wanted_headers).any? } + return parsed_output if result.success? + end - return parsed_output if result.success? + result.assert_success! end - - nil end # Check if a URL is protected by CloudFlare (e.g. badlion.net and jaxx.io).