Merge pull request #15389 from samford/livecheck/header_match-fixes
Strategy#page_headers: Update for #curl_headers
This commit is contained in:
commit
0a43a09eb3
@ -182,16 +182,18 @@ module Homebrew
|
||||
headers = []
|
||||
|
||||
[:default, :browser].each do |user_agent|
|
||||
output, _, status = curl_headers(
|
||||
url,
|
||||
wanted_headers: ["location", "content-disposition"],
|
||||
use_homebrew_curl: homebrew_curl,
|
||||
user_agent: user_agent,
|
||||
**DEFAULT_CURL_OPTIONS,
|
||||
)
|
||||
next unless status.success?
|
||||
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 = parse_curl_output(output, max_iterations: MAX_PARSE_ITERATIONS)
|
||||
parsed_output[:responses].each { |response| headers << response[:headers] }
|
||||
break if headers.present?
|
||||
end
|
||||
|
||||
@ -216,9 +216,14 @@ module Utils
|
||||
if result.success? || result.exit_status == 22
|
||||
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 request_args.empty?
|
||||
# If we didn't get any wanted header yet, retry using `GET`.
|
||||
next if wanted_headers.any? &&
|
||||
parsed_output.fetch(:responses).none? { |r| (r.fetch(:headers).keys & wanted_headers).any? }
|
||||
|
||||
# Some CDNs respond with 400 codes for `HEAD` but resolve with `GET`.
|
||||
next if (400..499).cover?(parsed_output.fetch(:responses).last&.fetch(:status_code).to_i)
|
||||
end
|
||||
|
||||
return parsed_output if result.success?
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user