utils/curl: extract status checks into method.

This commit is contained in:
Mike McQuaid 2019-09-18 10:32:13 +01:00
parent 78a0105fe2
commit fbc13f05dd
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70

View File

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