diff options
author | Andre Arko <andre@arko.net> | 2013-09-28 13:30:40 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2013-09-28 13:30:40 -0700 |
commit | bef536a77b39908a63ca2de09fbb52f8a94f1905 (patch) | |
tree | 0984c71737c580a7a62f32a476b1eea7099c1198 | |
parent | e82fde44e9d0a73efd1c88689210c7437673c82c (diff) | |
parent | 715609475ee783a3720c8b02a00746377d6d9a52 (diff) | |
download | bundler-bef536a77b39908a63ca2de09fbb52f8a94f1905.tar.gz |
Merge pull request #2649 from joyicecloud/user_agent
Add user agent to fetcher requests
-rw-r--r-- | lib/bundler.rb | 4 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 5 | ||||
-rw-r--r-- | lib/bundler/fetcher.rb | 65 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 2 | ||||
-rw-r--r-- | lib/bundler/ruby_version.rb | 10 |
5 files changed, 66 insertions, 20 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index a6481cf116..b537ed7156 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -357,6 +357,10 @@ module Bundler @git_present ||= Bundler.which("git") end + def ruby_version + @ruby_version ||= SystemRubyVersion.new + end + private def eval_yaml_gemspec(path, contents) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 4e538e6199..6c6a60b1bc 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -369,8 +369,7 @@ module Bundler def validate_ruby! return unless ruby_version - system_ruby_version = Bundler::SystemRubyVersion.new - if diff = ruby_version.diff(system_ruby_version) + if diff = ruby_version.diff(Bundler.ruby_version) problem, expected, actual = diff msg = case problem @@ -379,7 +378,7 @@ module Bundler when :version "Your Ruby version is #{actual}, but your Gemfile specified #{expected}" when :engine_version - "Your #{system_ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}" + "Your #{Bundler.ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}" when :patchlevel "Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}" end diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 8b05046003..ecffd36dd3 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -1,4 +1,5 @@ require 'bundler/vendored_persistent' +require 'securerandom' module Bundler @@ -57,6 +58,55 @@ module Bundler gem_path end + + def connection + return @connection if @connection + + needs_ssl = @remote_uri.scheme == "https" || + Bundler.settings[:ssl_verify_mode] || + Bundler.settings[:ssl_client_cert] + raise SSLError if needs_ssl && !defined(OpenSSL) + + @connection = Net::HTTP::Persistent.new 'bundler', :ENV + + if @remote_uri.scheme == "https" + @connection.verify_mode = (Bundler.settings[:ssl_verify_mode] || + OpenSSL::SSL::VERIFY_PEER) + @connection.cert_store = bundler_cert_store + end + + if Bundler.settings[:ssl_client_cert] + pem = File.read(Bundler.settings[:ssl_client_cert]) + @connection.cert = OpenSSL::X509::Certificate.new(pem) + @connection.key = OpenSSL::PKey::RSA.new(pem) + end + + @connection.read_timeout = @api_timeout + @connection.override_headers["User-Agent"] = user_agent + + @connection + end + + def user_agent + @user_agent ||= begin + ruby = Bundler.ruby_version + + agent = "bundler/#{Bundler::VERSION}" + agent += " rubygems/#{Gem::VERSION}" + agent += " ruby/#{ruby.version}" + agent += " (#{ruby.host})" + agent += " command/#{ARGV.join(" ")}" + + if ruby.engine != "ruby" + # engine_version raises on unknown engines + engine_version = ruby.engine_version rescue "???" + agent += " #{ruby.engine}/#{engine_version}" + end + # add a random ID so we can consolidate runs server-side + agent << " " << SecureRandom.hex(8) + end + end + end def initialize(remote_uri) @@ -70,21 +120,6 @@ module Bundler @remote_uri = remote_uri @public_uri = remote_uri.dup @public_uri.user, @public_uri.password = nil, nil # don't print these - if defined?(Net::HTTP::Persistent) - @connection = Net::HTTP::Persistent.new 'bundler', :ENV - @connection.verify_mode = (Bundler.settings[:ssl_verify_mode] || - OpenSSL::SSL::VERIFY_PEER) - @connection.cert_store = bundler_cert_store - if Bundler.settings[:ssl_client_cert] - pem = File.read(Bundler.settings[:ssl_client_cert]) - @connection.cert = OpenSSL::X509::Certificate.new(pem) - @connection.key = OpenSSL::PKey::RSA.new(pem) - end - else - raise SSLError if @remote_uri.scheme == "https" - @connection = Net::HTTP.new(@remote_uri.host, @remote_uri.port) - end - @connection.read_timeout = @api_timeout Socket.do_not_reverse_lookup = true end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 7470248c3a..ebc36f4c82 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -250,7 +250,7 @@ module Bundler spec.require_paths.each do |path| full_path = File.join(spec.full_gem_path, path) gem_path = Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)) - paths << gem_path.to_s.sub("#{SystemRubyVersion.new.engine}/#{RbConfig::CONFIG['ruby_version']}", '#{ruby_engine}/#{ruby_version}') + paths << gem_path.to_s.sub("#{Bundler.ruby_version.engine}/#{RbConfig::CONFIG['ruby_version']}", '#{ruby_engine}/#{ruby_version}') end end diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index bf44278b46..73ce6c7c3c 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -57,6 +57,14 @@ module Bundler nil end end + + def host + @host ||= [ + RbConfig::CONFIG["host_cpu"], + RbConfig::CONFIG["host_vendor"], + RbConfig::CONFIG["host_os"] + ].join("-") + end end # A subclass of RubyVersion that implements version, @@ -97,7 +105,7 @@ module Bundler when "jruby" JRUBY_VERSION.dup else - raise BundlerError, "That RUBY_ENGINE is not recognized" + raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized" nil end end |