audit: use new curl_args form.
This will use Curl’s default user agent to reduce homepage errors and provides a function that can be used for other audits to perform similar tests on URLs.
This commit is contained in:
parent
e6fb3c3114
commit
b3c6334d3c
@ -169,6 +169,33 @@ 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)
|
||||||
|
# The system Curl is too old and unreliable with HTTPS homepages on
|
||||||
|
# Yosemite and below.
|
||||||
|
return "200" unless DevelopmentTools.curl_handles_most_https_homepages?
|
||||||
|
|
||||||
|
extra_args = [
|
||||||
|
"--connect-timeout", "15",
|
||||||
|
"--output", "/dev/null",
|
||||||
|
"--write-out", "%{http_code}"
|
||||||
|
]
|
||||||
|
extra_args << "--range" << "0-0" if range
|
||||||
|
extra_args << url
|
||||||
|
|
||||||
|
args = curl_args(
|
||||||
|
extra_args: extra_args,
|
||||||
|
show_output: true,
|
||||||
|
default_user_agent: true
|
||||||
|
)
|
||||||
|
retries = 3
|
||||||
|
status_code = nil
|
||||||
|
retries.times do
|
||||||
|
status_code = Open3.popen3(*args) { |_, stdout, _, _| stdout.read }
|
||||||
|
break if status_code.start_with? "20"
|
||||||
|
end
|
||||||
|
status_code
|
||||||
|
end
|
||||||
|
|
||||||
def audit_style
|
def audit_style
|
||||||
return unless @style_offenses
|
return unless @style_offenses
|
||||||
display_cop_names = ARGV.include?("--display-cop-names")
|
display_cop_names = ARGV.include?("--display-cop-names")
|
||||||
@ -570,19 +597,8 @@ class FormulaAuditor
|
|||||||
|
|
||||||
return unless @online
|
return unless @online
|
||||||
|
|
||||||
# The system Curl is too old and unreliable with HTTPS homepages on
|
status_code = url_status_code(homepage)
|
||||||
# Yosemite and below.
|
|
||||||
return unless MacOS.version >= :el_capitan
|
|
||||||
|
|
||||||
retries = 3
|
|
||||||
retries.times do
|
|
||||||
status_code, = curl_output "--connect-timeout", "15",
|
|
||||||
"--output", "/dev/null",
|
|
||||||
"--range", "0-0",
|
|
||||||
"--write-out", "%{http_code}",
|
|
||||||
homepage
|
|
||||||
return if status_code.start_with? "20"
|
return if status_code.start_with? "20"
|
||||||
end
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -119,6 +119,10 @@ class DevelopmentTools
|
|||||||
@clang_version = @clang_build_version = nil
|
@clang_version = @clang_build_version = nil
|
||||||
@non_apple_gcc_version = {}
|
@non_apple_gcc_version = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def curl_handles_most_https_homepages?
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,5 +76,10 @@ class DevelopmentTools
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def curl_handles_most_https_homepages?
|
||||||
|
# The system Curl is too old for some modern HTTPS homepages on Yosemite.
|
||||||
|
MacOS.version >= :el_capitan
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user