Class: Gem::Request
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/rubygems/request.rb |
Class Method Summary
- .configure_connection_for_https(connection, cert_files)
- .get_cert_files
-
.get_proxy_from_env(scheme = 'http')
Returns a proxy URI for the given
scheme
if one is set in the environment variables. - .new(uri, request_class, last_modified, pool) ⇒ Request constructor
Instance Attribute Summary
DefaultUserInteraction - Included
Instance Method Summary
- #cert_files
-
#connection_for(uri)
Creates or an HTTP connection based on
uri
, or retrieves an existing connection, using a proxy if needed. - #fetch {|request| ... }
- #proxy_uri
-
#reset(connection)
Resets HTTP connection
connection
. - #user_agent
UserInteraction - Included
#alert | Displays an alert |
#alert_error | Displays an error |
#alert_warning | Displays a warning |
#ask | Asks a |
#ask_for_password | Asks for a password with a |
#ask_yes_no | Asks a yes or no |
#choose_from_list | Asks the user to answer |
#say | Displays the given |
#terminate_interaction | Terminates the RubyGems process with the given |
#verbose | Calls |
DefaultUserInteraction - Included
Constructor Details
.new(uri, request_class, last_modified, pool) ⇒ Request
# File 'lib/rubygems/request.rb', line 28
def initialize(uri, request_class, last_modified, pool) @uri = uri @request_class = request_class @last_modified = last_modified @requests = Hash.new 0 @user_agent = user_agent @connection_pool = pool end
Class Method Details
.configure_connection_for_https(connection, cert_files)
[ GitHub ]# File 'lib/rubygems/request.rb', line 46
def self.configure_connection_for_https(connection, cert_files) require 'net/https' connection.use_ssl = true connection.verify_mode = Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER store = OpenSSL::X509::Store.new if Gem.configuration.ssl_client_cert then pem = File.read Gem.configuration.ssl_client_cert connection.cert = OpenSSL::X509::Certificate.new pem connection.key = OpenSSL::PKey::RSA.new pem end store.set_default_paths cert_files.each do |ssl_cert_file| store.add_file ssl_cert_file end if Gem.configuration.ssl_ca_cert if File.directory? Gem.configuration.ssl_ca_cert store.add_path Gem.configuration.ssl_ca_cert else store.add_file Gem.configuration.ssl_ca_cert end end connection.cert_store = store connection rescue LoadError => e raise unless (e.respond_to?(:path) && e.path == 'openssl') || e. =~ / -- openssl$/ raise Gem::Exception.new( 'Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources') end
.get_cert_files
[ GitHub ]# File 'lib/rubygems/request.rb', line 41
def self.get_cert_files pattern = File. ("./ssl_certs/*.pem", File.dirname(__FILE__)) Dir.glob(pattern) end
.get_proxy_from_env(scheme = 'http')
Returns a proxy URI for the given scheme
if one is set in the environment variables.
# File 'lib/rubygems/request.rb', line 116
def self.get_proxy_from_env scheme = 'http' _scheme = scheme.downcase _SCHEME = scheme.upcase env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"] no_env_proxy = env_proxy.nil? || env_proxy.empty? return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http' return :no_proxy if no_env_proxy uri = URI(Gem::UriFormatter.new(env_proxy).normalize) if uri and uri.user.nil? and uri.password.nil? then user = ENV["#{_scheme}_proxy_user"] || ENV["#{_SCHEME}_PROXY_USER"] password = ENV["#{_scheme}_proxy_pass"] || ENV["#{_SCHEME}_PROXY_PASS"] uri.user = Gem::UriFormatter.new(user).escape uri.password = Gem::UriFormatter.new(password).escape end uri end
Instance Method Details
#cert_files
[ GitHub ]# File 'lib/rubygems/request.rb', line 39
def cert_files; @connection_pool.cert_files; end
#connection_for(uri)
Creates or an HTTP connection based on uri
, or retrieves an existing connection, using a proxy if needed.
# File 'lib/rubygems/request.rb', line 84
def connection_for(uri) @connection_pool.checkout rescue defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : Errno::EHOSTDOWN, Errno::EHOSTDOWN => e raise Gem::RemoteFetcher::FetchError.new(e., uri) end
#fetch {|request| ... }
# File 'lib/rubygems/request.rb', line 91
def fetch request = @request_class.new @uri.request_uri unless @uri.nil? || @uri.user.nil? || @uri.user.empty? then request.basic_auth Gem::UriFormatter.new(@uri.user).unescape, Gem::UriFormatter.new(@uri.password).unescape end request.add_field 'User-Agent', @user_agent request.add_field 'Connection', 'keep-alive' request.add_field 'Keep-Alive', '30' if @last_modified then request.add_field 'If-Modified-Since', @last_modified.httpdate end yield request if block_given? perform_request request end
#proxy_uri
[ GitHub ]# File 'lib/rubygems/request.rb', line 38
def proxy_uri; @connection_pool.proxy_uri; end
#reset(connection)
Resets HTTP connection connection
.
# File 'lib/rubygems/request.rb', line 213
def reset(connection) @requests.delete connection.object_id connection.finish connection.start end
#user_agent
[ GitHub ]# File 'lib/rubygems/request.rb', line 220
def user_agent ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}" ruby_version = RUBY_VERSION ruby_version += 'dev' if RUBY_PATCHLEVEL == -1 ua << " Ruby/#{ruby_version} (#{RUBY_RELEASE_DATE}" if RUBY_PATCHLEVEL >= 0 then ua << " patchlevel #{RUBY_PATCHLEVEL}" elsif defined?(RUBY_REVISION) then ua << " revision #{RUBY_REVISION}" end ua << ")" ua << " #{RUBY_ENGINE}" if defined?(RUBY_ENGINE) and RUBY_ENGINE != 'ruby' ua end