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 <mike@mikemcquaid.com>
This commit is contained in:
Indrajit Raychaudhuri 2015-07-08 23:53:20 -05:00 committed by Mike McQuaid
parent 6a534f569d
commit 7c890261ac

View File

@ -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