Merge pull request #6463 from alebcay/1xx-status-codes

utils/curl.rb: accept 1xx HTTP status codes
This commit is contained in:
Mike McQuaid 2019-09-18 11:26:16 +01:00 committed by GitHub
commit aacdf4f2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,7 +94,7 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false,
user_agents.each do |ua| user_agents.each do |ua|
details = curl_http_content_headers_and_checksum(url, hash_needed: hash_needed, user_agent: ua) details = curl_http_content_headers_and_checksum(url, hash_needed: hash_needed, user_agent: ua)
user_agent = ua user_agent = ua
break if details[:status].to_s.start_with?("2") break if http_status_ok?(details[:status])
end end
unless details[:status] unless details[:status]
@ -104,7 +104,7 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false,
return "The URL #{url} is not reachable" return "The URL #{url} is not reachable"
end end
unless details[:status].start_with? "2" unless http_status_ok?(details[:status])
return "The URL #{url} is not reachable (HTTP status code #{details[:status]})" return "The URL #{url} is not reachable (HTTP status code #{details[:status]})"
end end
@ -119,8 +119,8 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false,
secure_details = secure_details =
curl_http_content_headers_and_checksum(secure_url, hash_needed: true, user_agent: user_agent) curl_http_content_headers_and_checksum(secure_url, hash_needed: true, user_agent: user_agent)
if !details[:status].to_s.start_with?("2") || if !http_status_ok?(details[:status]) ||
!secure_details[:status].to_s.start_with?("2") !http_status_ok?(secure_details[:status])
return return
end end
@ -192,3 +192,7 @@ def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent:
file: output, file: output,
} }
end end
def http_status_ok?(status)
(100..299).cover?(status.to_i)
end