aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/curl.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/utils/curl.rb')
-rw-r--r--Library/Homebrew/utils/curl.rb49
1 files changed, 31 insertions, 18 deletions
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb
index 5a40ae846..52d03c93e 100644
--- a/Library/Homebrew/utils/curl.rb
+++ b/Library/Homebrew/utils/curl.rb
@@ -1,42 +1,55 @@
require "pathname"
require "open3"
-def curl_args(options = {})
+def curl_executable
curl = Pathname.new ENV["HOMEBREW_CURL"]
curl = Pathname.new "/usr/bin/curl" unless curl.exist?
- raise "#{curl} is not executable" unless curl.exist? && curl.executable?
+ return curl if curl.executable?
+ raise "#{curl} is not executable"
+end
+def curl_args(*extra_args, show_output: false, user_agent: :default)
args = [
- curl.to_s,
- "--remote-time",
- "--location",
+ curl_executable.to_s,
+ "--show-error",
]
- case options[:user_agent]
- when :browser
- args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI
+ args << "--user-agent" << case user_agent
+ when :browser, :fake
+ HOMEBREW_USER_AGENT_FAKE_SAFARI
+ when :default
+ HOMEBREW_USER_AGENT_CURL
else
- args << "--user-agent" << HOMEBREW_USER_AGENT_CURL
+ user_agent
end
- unless options[:show_output]
+ unless show_output
+ args << "--fail"
args << "--progress-bar" unless ARGV.verbose?
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"]
- args << "--fail"
args << "--silent" if !$stdout.tty? || ENV["TRAVIS"]
end
- args += options[:extra_args] if options[:extra_args]
- args
+ args + extra_args
end
def curl(*args)
- safe_system(*curl_args(extra_args: args))
+ safe_system(*curl_args(*args))
end
-def curl_output(*args)
- curl_args = curl_args(extra_args: args, show_output: true)
- Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread|
- [stdout.read, stderr.read, wait_thread.value]
+def curl_download(*args, to: nil, **options)
+ continue_at ||= "-"
+ curl("--location", "--remote-time", "--continue-at", continue_at, "--output", to, *args, **options)
+rescue ErrorDuringExecution
+ # `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume.
+ if $CHILD_STATUS.exitstatus == 33 && continue_at == "-"
+ continue_at = "0"
+ retry
end
+
+ raise
+end
+
+def curl_output(*args, **options)
+ Open3.capture3(*curl_args(*args, show_output: true, **options))
end