Sha256: 26c20dc48b0b71bfd6e3d4321e6f0444a2bdaae3b7ff9744922c65c8a7d6fb3d

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

# Rely on autoloading instead of explicit require; helps avoid the "already
# initialized constant" warning on Ruby 1.8.7 when NetHttp is refereced below.
# require 'faraday/adapter/net_http'

module Faraday
  class Adapter
    class NetHttpPersistent < NetHttp
      dependency 'net/http/persistent'

      def net_http_connection(env)
        proxy_uri = nil
        if (proxy = env[:request][:proxy])
          proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s)
          proxy_uri.user = proxy_uri.password = nil
          # awful patch for net-http-persistent 2.8 not unescaping user/password
          (class << proxy_uri; self; end).class_eval do
            define_method(:user) { proxy[:user] }
            define_method(:password) { proxy[:password] }
          end if proxy[:user]
        end

        if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
          Net::HTTP::Persistent.new(name: 'Faraday', proxy: proxy_uri)
        else
          Net::HTTP::Persistent.new('Faraday', proxy_uri)
        end
      end

      def perform_request(http, env)
        http.request env[:url], create_request(env)
      rescue Errno::ETIMEDOUT => error
        raise Faraday::Error::TimeoutError, error
      rescue Net::HTTP::Persistent::Error => error
        if error.message.include? 'Timeout'
          raise Faraday::Error::TimeoutError, error
        elsif error.message.include? 'connection refused'
          raise Faraday::Error::ConnectionFailed, error
        else
          raise
        end
      end

      def configure_ssl(http, ssl)
        http.verify_mode  = ssl_verify_mode(ssl)
        http.cert_store   = ssl_cert_store(ssl)

        http.certificate  = ssl[:client_cert]  if ssl[:client_cert]
        http.private_key  = ssl[:client_key]   if ssl[:client_key]
        http.ca_file      = ssl[:ca_file]      if ssl[:ca_file]
        http.ssl_version  = ssl[:version]      if ssl[:version]
      end
    end
  end
end

Version data entries

9 entries across 6 versions & 2 rubygems

Version Path
tdiary-5.0.8 vendor/bundle/gems/faraday-0.13.1/lib/faraday/adapter/net_http_persistent.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http_persistent.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/faraday-0.13.1/lib/faraday/adapter/net_http_persistent.rb
tdiary-5.0.8 vendor/bundle/gems/faraday-0.14.0/lib/faraday/adapter/net_http_persistent.rb
faraday-0.14.0 lib/faraday/adapter/net_http_persistent.rb
tdiary-5.0.7 vendor/bundle/gems/faraday-0.13.1/lib/faraday/adapter/net_http_persistent.rb
tdiary-5.0.6 vendor/bundle/gems/faraday-0.13.1/lib/faraday/adapter/net_http_persistent.rb
faraday-0.13.1 lib/faraday/adapter/net_http_persistent.rb
faraday-0.13.0 lib/faraday/adapter/net_http_persistent.rb