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 = [] headers = []
[:default, :browser].each do |user_agent| [:default, :browser].each do |user_agent|
output, _, status = curl_headers( parsed_output = curl_headers(
url, url,
wanted_headers: ["location", "content-disposition"], wanted_headers: ["location", "content-disposition"],
use_homebrew_curl: homebrew_curl, use_homebrew_curl: homebrew_curl,
user_agent: user_agent, user_agent: user_agent,
**DEFAULT_CURL_OPTIONS, **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] } parsed_output[:responses].each { |response| headers << response[:headers] }
break if headers.present? break if headers.present?
end end

View File

@ -213,7 +213,8 @@ 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.
if result.success? || result.exit_status == 22 next 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`. # If we didn't get any wanted header yet, retry using `GET`.
@ -223,8 +224,7 @@ module Utils
return parsed_output if result.success? return parsed_output if result.success?
end end
result.assert_success! nil
end
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).