diff --git a/Library/Homebrew/livecheck/strategy.rb b/Library/Homebrew/livecheck/strategy.rb index 72df2f4934..d269cefdd9 100644 --- a/Library/Homebrew/livecheck/strategy.rb +++ b/Library/Homebrew/livecheck/strategy.rb @@ -182,16 +182,15 @@ module Homebrew headers = [] [:default, :browser].each do |user_agent| - output, _, status = curl_headers( + parsed_output = curl_headers( url, wanted_headers: ["location", "content-disposition"], use_homebrew_curl: homebrew_curl, user_agent: user_agent, **DEFAULT_CURL_OPTIONS, ) - next unless status.success? + next if parsed_output.blank? - parsed_output = parse_curl_output(output, max_iterations: MAX_PARSE_ITERATIONS) parsed_output[:responses].each { |response| headers << response[:headers] } break if headers.present? end diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 4b2d3b227f..963f4e650c 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. - if result.success? || result.exit_status == 22 - parsed_output = parse_curl_output(result.stdout) + next if !result.success? && result.exit_status != 22 - # 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? } + parsed_output = parse_curl_output(result.stdout) - return parsed_output if result.success? - end + # 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? } - result.assert_success! + return parsed_output if result.success? end + + nil end # Check if a URL is protected by CloudFlare (e.g. badlion.net and jaxx.io).