lib/core/transports.rb in buildr-1.1.1 vs lib/core/transports.rb in buildr-1.1.2
- old
+ new
@@ -25,11 +25,26 @@
method_missing :mkdir, first, path, attrs
end
end
end
+# Monkeypatching Net::HTTP to solve keep_alive bug, see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10818
+module Net
+ class HTTP
+ def keep_alive?(req, res)
+ return false if /close/i =~ req['connection'].to_s
+ return false if @seems_1_0_server
+ return false if /close/i =~ res['connection'].to_s
+ return true if /keep-alive/i =~ res['connection'].to_s
+ return false if /close/i =~ res['proxy-connection'].to_s
+ return true if /keep-alive/i =~ res['proxy-connection'].to_s
+ (@curr_http_version == '1.1')
+ end
+ end
+end
+
module Buildr
# Transports are used for downloading artifacts from remote repositories, uploading
# artifacts to deployment repositories, and anything else you need to move around.
#
@@ -72,15 +87,15 @@
# :call-seq:
# download(url, target, options?)
#
# Convenience method for downloading a single file from the specified
# URL to the target file.
- def download(url, target, options = nil)
+ def download(url, target, options = nil, &block)
uri = URI.parse(url.to_s)
path, uri.path = uri.path, ""
const_get(uri.scheme.upcase).perform(uri, options) do |transport|
- transport.download(path, target)
+ transport.download(path, target, &block)
end
end
end
@@ -236,11 +251,13 @@
end
class Digester #:nodoc:
def initialize(types)
- types ||= [ "md5", "sha1" ]
+ # Digests disabled for now, we have a keep-alive problem with Net::HTTP.
+ #types ||= [ "md5", "sha1" ]
+ types ||= []
@digests = types.inject({}) do |hash, type|
hash[type.to_s.downcase] = Digest.const_get(type.to_s.upcase).new
hash
end
end
@@ -302,10 +319,10 @@
puts "Not modified since last download" if Rake.application.options.trace
when Net::HTTPRedirection
# Try to download from the new URI, handle relative redirects.
puts "Redirected to #{response['Location']}" if Rake.application.options.trace
- last_modified = Transports.download(@uri + URI.parse(response["location"]), target, @options)
+ last_modified = Transports.download(@uri + URI.parse(response["location"]), target, @options, &block)
when Net::HTTPOK
puts "Downloading #{@uri}/#{path}" if verbose
last_modified = Time.parse(response["Last-Modified"] || "")
with_progress_bar path.split("/").last, response.content_length do |progress|