Class: Faraday::Adapter::NetHttpPersistent

Inherits:
NetHttp show all
Defined in:
lib/faraday/adapter/net_http_persistent.rb

Constant Summary

Constants inherited from NetHttp

Faraday::Adapter::NetHttp::NET_HTTP_EXCEPTIONS

Constants inherited from Faraday::Adapter

CONTENT_LENGTH

Instance Attribute Summary

Attributes included from Parallelism

#supports_parallel

Instance Method Summary collapse

Methods inherited from NetHttp

#call, #create_request, #net_http_connection, #ssl_cert_store, #ssl_verify_mode

Methods inherited from Faraday::Adapter

#call, #save_response

Methods included from Faraday::AutoloadHelper

#all_loaded_constants, #autoload_all, #load_autoloaded_constants

Methods included from Parallelism

#inherited, #supports_parallel?

Methods inherited from Middleware

dependency, inherited, #initialize, loaded?, new

Methods included from MiddlewareRegistry

#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware

Constructor Details

This class inherits a constructor from Faraday::Middleware

Instance Method Details

#configure_ssl(http, ssl) ⇒ Object


38
39
40
41
42
43
44
45
46
# File 'lib/faraday/adapter/net_http_persistent.rb', line 38

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

#perform_request(http, env) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/faraday/adapter/net_http_persistent.rb', line 24

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

#with_net_http_connection(env) {|Net::HTTP::Persistent.new 'Faraday', proxy_uri| ... } ⇒ Object

Yields:

  • (Net::HTTP::Persistent.new 'Faraday', proxy_uri)

10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/faraday/adapter/net_http_persistent.rb', line 10

def with_net_http_connection(env)
  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

  yield Net::HTTP::Persistent.new 'Faraday', proxy_uri
end