aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cask')
-rw-r--r--Library/Homebrew/cask/lib/hbc/audit.rb10
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask_loader.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/download_strategy.rb28
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/appcast.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/url.rb11
-rw-r--r--Library/Homebrew/cask/lib/hbc/verify/gpg.rb2
6 files changed, 21 insertions, 38 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb
index cee1fe807..b8bb6ab81 100644
--- a/Library/Homebrew/cask/lib/hbc/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/audit.rb
@@ -143,7 +143,15 @@ module Hbc
def check_appcast_http_code
odebug "Verifying appcast returns 200 HTTP response code"
- result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false)
+
+ curl_executable, *args = curl_args(
+ "--compressed", "--location", "--fail",
+ "--write-out", "%{http_code}",
+ "--output", "/dev/null",
+ cask.appcast,
+ user_agent: :fake
+ )
+ result = @command.run(curl_executable, args: args, print_stderr: false)
if result.success?
http_code = result.stdout.chomp
add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200"
diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
index 500314671..dd9c61089 100644
--- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
@@ -71,7 +71,7 @@ module Hbc
begin
ohai "Downloading #{url}."
- curl url, "-o", path
+ curl_download url, to: path
rescue ErrorDuringExecution
raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.")
end
diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb
index fb4319f5e..245ad4ade 100644
--- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb
+++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb
@@ -90,13 +90,8 @@ module Hbc
end
end
- def downloaded_size
- temporary_path.size? || 0
- end
-
def _fetch
- odebug "Calling curl with args #{cask_curl_args}"
- curl(*cask_curl_args)
+ curl_download url, *cask_curl_args, to: temporary_path, user_agent: uri_object.user_agent
end
def fetch
@@ -131,23 +126,7 @@ module Hbc
private
def cask_curl_args
- default_curl_args.tap do |args|
- args.concat(user_agent_args)
- args.concat(cookies_args)
- args.concat(referer_args)
- end
- end
-
- def default_curl_args
- [url, "-C", downloaded_size, "-o", temporary_path]
- end
-
- def user_agent_args
- if uri_object.user_agent
- ["-A", uri_object.user_agent]
- else
- []
- end
+ cookies_args + referer_args
end
def cookies_args
@@ -181,8 +160,7 @@ module Hbc
class CurlPostDownloadStrategy < CurlDownloadStrategy
def cask_curl_args
- super
- default_curl_args.concat(post_args)
+ super.concat(post_args)
end
def post_args
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
index d302d0946..fc7e83a20 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
@@ -12,7 +12,11 @@ module Hbc
end
def calculate_checkpoint
- result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--fail", @uri], print_stderr: false)
+ curl_executable, *args = curl_args(
+ "--compressed", "--location", "--fail", @uri,
+ user_agent: :fake
+ )
+ result = SystemCommand.run(curl_executable, args: args, print_stderr: false)
checkpoint = if result.success?
processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}m, "")
diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb
index 15da2ced2..8c652657b 100644
--- a/Library/Homebrew/cask/lib/hbc/url.rb
+++ b/Library/Homebrew/cask/lib/hbc/url.rb
@@ -1,8 +1,6 @@
module Hbc
class URL
- FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io".freeze
-
- attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data
+ attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data, :user_agent
extend Forwardable
def_delegators :uri, :path, :scheme, :to_s
@@ -17,7 +15,7 @@ module Hbc
def initialize(uri, options = {})
@uri = Hbc::UnderscoreSupportingURI.parse(uri)
- @user_agent = options[:user_agent]
+ @user_agent = options.fetch(:user_agent, :default)
@cookies = options[:cookies]
@referer = options[:referer]
@using = options[:using]
@@ -25,10 +23,5 @@ module Hbc
@trust_cert = options[:trust_cert]
@data = options[:data]
end
-
- def user_agent
- return FAKE_USER_AGENT if @user_agent == :fake
- @user_agent
- end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb
index dbb537756..f4996a5b5 100644
--- a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb
+++ b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb
@@ -33,7 +33,7 @@ module Hbc
meta_dir = cached || cask.metadata_subdir("gpg", :now, true)
sig_path = meta_dir.join("signature.asc")
- curl(cask.gpg.signature, "-o", sig_path.to_s) unless cached || force
+ curl_download cask.gpg.signature, to: sig_path unless cached || force
sig_path
end