class Bundler::Fetcher

def connection

def connection
  @connection ||= begin
    needs_ssl = remote_uri.scheme == "https" ||
      Bundler.settings[:ssl_verify_mode] ||
      Bundler.settings[:ssl_client_cert]
    raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)
    con = Bundler::Persistent::Net::HTTP::Persistent.new "bundler", :ENV
    if gem_proxy = Bundler.rubygems.configuration[:http_proxy]
      con.proxy = URI.parse(gem_proxy) if gem_proxy != :no_proxy
    end
    if remote_uri.scheme == "https"
      con.verify_mode = (Bundler.settings[:ssl_verify_mode] ||
        OpenSSL::SSL::VERIFY_PEER)
      con.cert_store = bundler_cert_store
    end
    if Bundler.settings[:ssl_client_cert]
      pem = File.read(Bundler.settings[:ssl_client_cert])
      con.cert = OpenSSL::X509::Certificate.new(pem)
      con.key  = OpenSSL::PKey::RSA.new(pem)
    end
    con.read_timeout = Fetcher.api_timeout
    con.open_timeout = Fetcher.api_timeout
    con.override_headers["User-Agent"] = user_agent
    con.override_headers["X-Gemfile-Source"] = @remote.original_uri.to_s if @remote.original_uri
    con
  end
end