From 7c890261ac500da49acd801aebe244d9d12f93e3 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Wed, 8 Jul 2015 23:53:20 -0500 Subject: [PATCH] download_strategy: private method allowing extra curl options. This allows some curl options to be always passed to curl, with raw head calls (`curl -I`) (in `CurlDownloadStrategy#actual_urls`) or with actual `curl` (in `CurlDownloadStrategy#curl`). This also avoid the need for overriding whole `_fetch` in a few cases and just override `_curl_opts` to append additional options instead. Closes Homebrew/homebrew#41506. Signed-off-by: Mike McQuaid --- Library/Homebrew/download_strategy.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 6ee032a716..12ee8a6816 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -323,9 +323,18 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy curl @url, "-C", downloaded_size, "-o", temporary_path end + # Curl options to be always passed to curl, + # with raw head calls (`curl -I`) or with actual `fetch`. + def _curl_opts + copts = [] + copts << "--user" << meta.fetch(:user) if meta.key?(:user) + copts + end + def actual_urls urls = [] - Utils.popen_read("curl", "-I", "-L", @url).scan(/^Location: (.+)$/).map do |m| + curl_args = _curl_opts << "-I" << "-L" << @url + Utils.popen_read("curl", *curl_args).scan(/^Location: (.+)$/).map do |m| urls << URI.join(urls.last || @url, m.first.chomp).to_s end urls @@ -336,8 +345,8 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy end def curl(*args) + args.concat _curl_opts args << '--connect-timeout' << '5' unless mirrors.empty? - args << "--user" << meta.fetch(:user) if meta.key?(:user) super end end @@ -390,8 +399,8 @@ end # Download from an SSL3-only host. class CurlSSL3DownloadStrategy < CurlDownloadStrategy - def _fetch - curl @url, '-3', '-C', downloaded_size, '-o', temporary_path + def _curl_opts + super << '-3' end end