Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/curl.rb: accept 1xx HTTP status codes #6463

Merged
merged 2 commits into from Sep 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions Library/Homebrew/utils/curl.rb
Expand Up @@ -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 details[:status].to_s.start_with?("2")
break if http_status_ok?(details[:status])
end

unless details[:status]
Expand All @@ -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 details[:status].start_with? "2"
unless http_status_ok?(details[:status])
return "The URL #{url} is not reachable (HTTP status code #{details[:status]})"
end

Expand All @@ -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 !details[:status].to_s.start_with?("2") ||
!secure_details[:status].to_s.start_with?("2")
if !http_status_ok?(details[:status]) ||
!http_status_ok?(secure_details[:status])
return
end

Expand Down Expand Up @@ -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