summaryrefslogtreecommitdiff
path: root/lib/rubygems/remote_fetcher.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-30 00:54:12 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-30 00:54:12 +0000
commite00d5437d1453f0ec4fbc980a81c15630624eb71 (patch)
tree07c1340a8c4ea3d0b7ae2f209866af85de089f27 /lib/rubygems/remote_fetcher.rb
parentf363bbdf1042562e40aaccbd1bdd7b783c096ff0 (diff)
* lib/rubygems: Update to RubyGems HEAD(60d7972).
this version contains pull requests number of #1343, #1356, #1357, #1363 at https://github.com/rubygems/rubygems/pulls * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/remote_fetcher.rb')
-rw-r--r--lib/rubygems/remote_fetcher.rb28
1 files changed, 23 insertions, 5 deletions
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index e3c78af908..8c7ee78f84 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -51,6 +51,8 @@ class Gem::RemoteFetcher
@fetcher ||= self.new Gem.configuration[:http_proxy]
end
+ attr_accessor :headers
+
##
# Initialize a remote fetcher using the source URI and possible proxy
# information.
@@ -64,8 +66,11 @@ class Gem::RemoteFetcher
#
# +dns+: An object to use for DNS resolution of the API endpoint.
# By default, use Resolv::DNS.
+ #
+ # +headers+: A set of additional HTTP headers to be sent to the server when
+ # fetching the gem.
- def initialize(proxy=nil, dns=Resolv::DNS.new)
+ def initialize(proxy=nil, dns=Resolv::DNS.new, headers={})
require 'net/http'
require 'stringio'
require 'time'
@@ -79,6 +84,7 @@ class Gem::RemoteFetcher
@cert_files = Gem::Request.get_cert_files
@dns = dns
+ @headers = headers
end
##
@@ -235,7 +241,9 @@ class Gem::RemoteFetcher
def fetch_http uri, last_modified = nil, head = false, depth = 0
fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
- response = request uri, fetch_type, last_modified
+ response = request uri, fetch_type, last_modified do |req|
+ headers.each { |k,v| req.add_field(k,v) }
+ end
case response
when Net::HTTPOK, Net::HTTPNotModified then
@@ -313,9 +321,19 @@ class Gem::RemoteFetcher
end
if update and path
- open(path, 'wb') do |io|
- io.flock(File::LOCK_EX)
- io.write data
+ begin
+ open(path, 'wb') do |io|
+ io.flock(File::LOCK_EX)
+ io.write data
+ end
+ rescue Errno::ENOLCK # NFS
+ if Thread.main != Thread.current
+ raise
+ else
+ open(path, 'wb') do |io|
+ io.write data
+ end
+ end
end
end