From 16f3a05e4565b70bcc57010b99034da9da231e56 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Mon, 8 May 2023 17:40:51 -0400 Subject: [PATCH] Strategy#page_headers: Update for #curl_headers `#curl_headers` was recently introduced into `Strategy#page_headers` but only the call was modified and the method wasn't updated to correctly work with the new return value, so all `HeaderMatch` checks immediately started failing with an error. This commit includes changes that return `#page_headers` to a working state. I've removed the `result.assert_success!` call because it prevents a few checks from being retried with `GET` (`firefox-cn`, `krisp`, `prepros`). --- Library/Homebrew/livecheck/strategy.rb | 5 ++--- Library/Homebrew/utils/curl.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) 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).