Class: Faraday::Adapter::Excon
- Inherits:
-
Faraday::Adapter
- Object
- Middleware
- Faraday::Adapter
- Faraday::Adapter::Excon
- Defined in:
- lib/faraday/adapter/excon.rb
Constant Summary
Constants inherited from Faraday::Adapter
Instance Attribute Summary
Attributes included from Parallelism
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, connection_options = {}) ⇒ Excon
constructor
A new instance of Excon.
-
#read_body(env) ⇒ Object
TODO: support streaming requests.
Methods inherited from Faraday::Adapter
adapter?, #prepend_proxy_auth_string, #save_response
Methods included from Faraday::AutoloadHelper
#all_loaded_constants, #autoload_all, #load_autoloaded_constants
Methods included from MiddlewareRegistry
#lookup_middleware, #register_middleware
Methods included from Parallelism
#inherited, #supports_parallel?
Methods inherited from Middleware
adapter?, dependency, inherited, loaded?, new
Constructor Details
#initialize(app, connection_options = {}) ⇒ Excon
Returns a new instance of Excon.
6 7 8 9 |
# File 'lib/faraday/adapter/excon.rb', line 6 def initialize(app, = {}) @connection_options = super(app) end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/faraday/adapter/excon.rb', line 11 def call(env) super opts = {} if env[:url].scheme == 'https' && ssl = env[:ssl] opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true) opts[:ssl_ca_path] = ssl[:ca_file] if ssl[:ca_file] end if ( req = env[:request] ) if req[:timeout] opts[:read_timeout] = req[:timeout] opts[:connect_timeout] = req[:timeout] opts[:write_timeout] = req[:timeout] end if req[:open_timeout] opts[:connect_timeout] = req[:open_timeout] opts[:write_timeout] = req[:open_timeout] end end conn = ::Excon.new(env[:url].to_s, opts.merge(@connection_options)) resp = conn.request \ :method => env[:method].to_s.upcase, :headers => env[:request_headers], :body => read_body(env) save_response(env, resp.status.to_i, resp.body, resp.headers) @app.call env rescue ::Excon::Errors::SocketError => err if err. =~ /\btimeout\b/ raise Error::TimeoutError, err else raise Error::ConnectionFailed, err end rescue ::Excon::Errors::Timeout => err raise Error::TimeoutError, err end |
#read_body(env) ⇒ Object
TODO: support streaming requests
54 55 56 |
# File 'lib/faraday/adapter/excon.rb', line 54 def read_body(env) env[:body].respond_to?(:read) ? env[:body].read : env[:body] end |