From 78a0105fe2cbc002081e729142b0927632c8ddb7 Mon Sep 17 00:00:00 2001 From: Caleb Xu Date: Mon, 16 Sep 2019 11:34:02 -0400 Subject: [PATCH 1/2] utils/curl.rb: accept 1xx HTTP status codes RFC 2616 states: A client MUST be prepared to accept one or more 1xx status responses prior to a regular response, even if the client does not expect a 100 (Continue) status message. Unexpected 1xx status responses MAY be ignored by a user agent. In the rare cases that we encounter a formula URL with a server that provides a preliminary 1xx status code, it seems that (at least during audit) we are failing on encountering this status code, even though retrieving the file will succeed without issues. --- Library/Homebrew/utils/curl.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 59be98dd49c6b..06e152ddc08ca 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -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 (100..299).include?(details[:status].to_i) 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 details[:status].start_with? "2" + unless (100..299).include?(details[:status].to_i) 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 !details[:status].to_s.start_with?("2") || - !secure_details[:status].to_s.start_with?("2") + if !(100..299).include?(details[:status].to_i) || + !(100..299).include?(secure_details[:status].to_i) return end From fbc13f05dd67656915c320cf33201f75af2d60ba Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 18 Sep 2019 10:32:13 +0100 Subject: [PATCH 2/2] utils/curl: extract status checks into method. --- Library/Homebrew/utils/curl.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 06e152ddc08ca..e3b4cc24dbe51 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -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