Merge pull request #1917 from MikeMcQuaid/homebrew-audit-tweak

audit: improve homepage audit reliability.
This commit is contained in:
Mike McQuaid 2017-01-27 08:46:19 +00:00 committed by GitHub
commit 858b406da1
2 changed files with 9 additions and 10 deletions

View File

@ -169,7 +169,7 @@ class FormulaAuditor
@specs = %w[stable devel head].map { |s| formula.send(s) }.compact @specs = %w[stable devel head].map { |s| formula.send(s) }.compact
end end
def url_status_code(url, range: false, user_agent: :default) def url_status_code(url, range: false)
# The system Curl is too old and unreliable with HTTPS homepages on # The system Curl is too old and unreliable with HTTPS homepages on
# Yosemite and below. # Yosemite and below.
return "200" unless DevelopmentTools.curl_handles_most_https_homepages? return "200" unless DevelopmentTools.curl_handles_most_https_homepages?
@ -182,14 +182,13 @@ class FormulaAuditor
extra_args << "--range" << "0-0" if range extra_args << "--range" << "0-0" if range
extra_args << url extra_args << url
args = curl_args(
extra_args: extra_args,
show_output: true,
user_agent: user_agent
)
retries = 3
status_code = nil status_code = nil
retries.times do [:browser, :default].each do |user_agent|
args = curl_args(
extra_args: extra_args,
show_output: true,
user_agent: user_agent
)
status_code = Open3.popen3(*args) { |_, stdout, _, _| stdout.read } status_code = Open3.popen3(*args) { |_, stdout, _, _| stdout.read }
break if status_code.start_with? "20" break if status_code.start_with? "20"
end end
@ -609,7 +608,7 @@ class FormulaAuditor
return unless @online return unless @online
status_code = url_status_code(homepage, user_agent: :browser) status_code = url_status_code(homepage)
return if status_code.start_with? "20" return if status_code.start_with? "20"
problem "The homepage #{homepage} is not reachable (HTTP status code #{status_code})" problem "The homepage #{homepage} is not reachable (HTTP status code #{status_code})"
end end

View File

@ -26,7 +26,7 @@ RUBY_BIN = RUBY_PATH.dirname
HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"] HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"]
HOMEBREW_USER_AGENT_RUBY = "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}".freeze HOMEBREW_USER_AGENT_RUBY = "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}".freeze
HOMEBREW_USER_AGENT_FAKE_SAFARI = "Mozilla/5.0 (#{ENV["HOMEBREW_SYSTEM"]}; #{ENV["HOMEBREW_PROCESSOR"]} #{ENV["HOMEBREW_OS_VERSION"]}) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0.2 Safari/602.3.12".freeze HOMEBREW_USER_AGENT_FAKE_SAFARI = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8".freeze
require "tap_constants" require "tap_constants"