CurlDownloadStrategy: move no insecure redirect check to _fetch

This mainly fixes the problems for subclasses of CurlDownloadStrategy.
More specifically it fixes two things:
 * It allows the no insecure redirect check to be applied to
   CurlApacheMirrorDownloadStrategy.
 * It fixes previous broken CurlPostDownloadStrategy.

Closes #280.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Xu Cheng 2016-05-26 20:03:17 +08:00
parent 8b61d7899b
commit 75ab94c8ea

View File

@ -284,17 +284,6 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
ohai "Downloading #{@url}" ohai "Downloading #{@url}"
unless cached_location.exist? unless cached_location.exist?
urls = actual_urls
unless urls.empty?
ohai "Downloading from #{urls.last}"
if !ENV["HOMEBREW_NO_INSECURE_REDIRECT"].nil? && @url.start_with?("https://") &&
urls.any? { |u| !u.start_with? "https://" }
puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set."
raise CurlDownloadStrategyError.new(@url)
end
@url = urls.last
end
had_incomplete_download = temporary_path.exist? had_incomplete_download = temporary_path.exist?
begin begin
_fetch _fetch
@ -334,6 +323,17 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
# Private method, can be overridden if needed. # Private method, can be overridden if needed.
def _fetch def _fetch
urls = actual_urls
unless urls.empty?
ohai "Downloading from #{urls.last}"
if !ENV["HOMEBREW_NO_INSECURE_REDIRECT"].nil? && @url.start_with?("https://") &&
urls.any? { |u| !u.start_with? "https://" }
puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set."
raise CurlDownloadStrategyError.new(@url)
end
@url = urls.last
end
curl @url, "-C", downloaded_size, "-o", temporary_path curl @url, "-C", downloaded_size, "-o", temporary_path
end end