Class: Faraday::Adapter::NetHttpPersistent
- Inherits:
-
Faraday::Adapter
- Object
- Faraday::Adapter
- Faraday::Adapter::NetHttpPersistent
- Defined in:
- lib/faraday/adapter/net_http_persistent.rb
Overview
Net::HTTP::Persistent adapter.
Constant Summary collapse
- NET_HTTP_EXCEPTIONS =
TODO (breaking): Enable this to make it consistent with net_http adapter.
See https://github.com/lostisland/faraday/issues/718#issuecomment-344549382
exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)
exceptions.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
- #close ⇒ Object
-
#initialize(app = nil, opts = {}, &block) ⇒ NetHttpPersistent
constructor
A new instance of NetHttpPersistent.
Constructor Details
#initialize(app = nil, opts = {}, &block) ⇒ NetHttpPersistent
Returns a new instance of NetHttpPersistent.
34 35 36 37 |
# File 'lib/faraday/adapter/net_http_persistent.rb', line 34 def initialize(app = nil, opts = {}, &block) @ssl_cert_store = nil super(app, opts, &block) end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/faraday/adapter/net_http_persistent.rb', line 39 def call(env) super connection(env) do |http| perform_request(http, env) rescue Net::HTTP::Persistent::Error => e raise Faraday::TimeoutError, e if e..include?("Timeout") raise Faraday::ConnectionFailed, e if e..include?("connection refused") raise rescue *NET_HTTP_EXCEPTIONS => e raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError) raise Faraday::ConnectionFailed, e end @app.call env rescue Timeout::Error, Errno::ETIMEDOUT => e raise Faraday::TimeoutError, e end |
#close ⇒ Object
59 60 61 |
# File 'lib/faraday/adapter/net_http_persistent.rb', line 59 def close @cached_connection&.shutdown end |