lib/core/transports.rb in buildr-1.0.0 vs lib/core/transports.rb in buildr-1.1.0

- old
+ new

@@ -34,10 +34,14 @@ # artifacts to deployment repositories, and anything else you need to move around. # # The HTTP transport is used for all URLs with the scheme http or https. You can only # use the HTTP transport to download artifacts. # + # The HTTP transport supports the following options: + # * :proxy -- Proxy server to use. A hash with the values host, port, user and password. + # You can also pass a URL (string or URI object). + # # The SFTP transport is used for all URLs with the schema sftp. You can only use the # SFTP transport to upload artifacts. # # The SFTP transport supports the following options: # * :username -- The username. @@ -267,19 +271,32 @@ class HTTP < Transport #:nodoc: def initialize(url, options) super - rake_check_options options, :digests if options - @http = Net::HTTP.start(@uri.host, @uri.port) + if options + rake_check_options options, :proxy, :digests + proxy = options[:proxy] + end + + case proxy + when Hash + @http = Net::HTTP.start(@uri.host, @uri.port, proxy[:host], proxy[:port], proxy[:user], proxy[:password]) + when URI, String + proxy = URI.parse(proxy.to_s) + @http = Net::HTTP.start(@uri.host, @uri.port, proxy.host, proxy.port, proxy.user, proxy.password) + else + @http = Net::HTTP.start(@uri.host, @uri.port) + end end def download(path, target = nil, &block) puts "Requesting #{@uri}/#{path} " if Rake.application.options.trace - last_modified = File.stat(target).mtime.utc if target && File.exist?(target) - headers = {} - headers["If-Modified-Since"] = CGI.rfc1123_date(last_modified) if last_modified + if target && File.exist?(target) + last_modified = File.stat(target).mtime.utc + headers = { "If-Modified-Since" => CGI.rfc1123_date(last_modified) } + end @http.request_get(@base_path + path, headers) do |response| case response when Net::HTTPNotModified # No modification, nothing to do. puts "Not modified since last download" if Rake.application.options.trace @@ -321,18 +338,17 @@ temp = Tempfile.open(File.basename(target)) temp.binmode download[ proc { |chunk| temp.write chunk } ] temp.close File.move temp.path, target - File.utime last_modified, last_modified, target else download[ block ] end end end when Net::HTTPNotFound - raise NotFound + raise NotFound, "Looking for #{@uri}/#{path} and all I got was a 404!" else fail "Failed to download #{@uri}/#{path}: #{response.message}" end end last_modified