Retry curl_headers on 400 codes.

This commit is contained in:
Markus Reiter 2023-05-09 07:40:15 +02:00
parent e493d0cb04
commit 4b787fdee2
No known key found for this signature in database
GPG Key ID: 245293B51702655B

View File

@ -216,9 +216,14 @@ module Utils
if result.success? || result.exit_status == 22 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 request_args.empty?
next if request_args.empty? && wanted_headers.any? && # If we didn't get any wanted header yet, retry using `GET`.
parsed_output.fetch(:responses).none? { |r| (r.fetch(:headers).keys & wanted_headers).any? } 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? return parsed_output if result.success?
end end