diff options
| author | Mike McQuaid | 2017-01-07 14:03:08 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2017-01-07 14:03:08 +0000 |
| commit | e7a81caaf4bc0468fdc302656efebd584e10a3f6 (patch) | |
| tree | 43f7af993518340e3e5bf9d95ec1bfc7d76901fd /Library | |
| parent | 2aac904eac522a4d746a852ecc244509f5cfdafa (diff) | |
| download | brew-e7a81caaf4bc0468fdc302656efebd584e10a3f6.tar.bz2 | |
Allow `brew audit` to fake a Safari user-agent.
This allows us to detect if homepages such as e.g. `aiccu` which
blocks `curl` are up or not.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/dev-cmd/audit.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/global.rb | 1 | ||||
| -rw-r--r-- | Library/Homebrew/utils/curl.rb | 5 |
3 files changed, 8 insertions, 4 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 601031d6e..6d43c51bf 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -169,7 +169,7 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def url_status_code(url, range: false) + def url_status_code(url, range: false, user_agent: :default) # The system Curl is too old and unreliable with HTTPS homepages on # Yosemite and below. return "200" unless DevelopmentTools.curl_handles_most_https_homepages? @@ -185,7 +185,7 @@ class FormulaAuditor args = curl_args( extra_args: extra_args, show_output: true, - default_user_agent: true + user_agent: user_agent ) retries = 3 status_code = nil @@ -597,7 +597,7 @@ class FormulaAuditor return unless @online - status_code = url_status_code(homepage) + status_code = url_status_code(homepage, user_agent: :browser) return if status_code.start_with? "20" problem "The homepage #{homepage} is not reachable (HTTP status code #{status_code})" end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 9a2f0c794..031178421 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -26,6 +26,7 @@ RUBY_BIN = RUBY_PATH.dirname 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_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 require "tap_constants" diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index eab623c40..5a40ae846 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -12,7 +12,10 @@ def curl_args(options = {}) "--location", ] - unless options[:default_user_agent] + case options[:user_agent] + when :browser + args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI + else args << "--user-agent" << HOMEBREW_USER_AGENT_CURL end |
