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`).
This commit is contained in:
Sam Ford 2023-05-08 17:40:51 -04:00
parent 82dc1d25ef
commit 16f3a05e45
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D
2 changed files with 10 additions and 11 deletions

View File

@ -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

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.
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).