Class: Faraday::Adapter::Excon
- Inherits:
-
Faraday::Adapter
- Object
- Faraday::Adapter
- Faraday::Adapter::Excon
- Defined in:
- lib/faraday/adapter/excon.rb
Overview
Excon adapter.
Constant Summary
Constants inherited from Faraday::Adapter
Instance Attribute Summary
Attributes included from DependencyLoader
Attributes included from Parallelism
Instance Method Summary collapse
- #call(env) ⇒ Object
- #create_connection(env, opts) ⇒ Excon
-
#read_body(env) ⇒ Object
TODO: support streaming requests.
Methods inherited from Faraday::Adapter
Methods included from MiddlewareRegistry
#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware, #unregister_middleware
Methods included from DependencyLoader
#dependency, #inherited, #loaded?, #new
Methods included from Parallelism
#inherited, #supports_parallel?
Methods included from Faraday::AutoloadHelper
#all_loaded_constants, #autoload_all, #load_autoloaded_constants
Constructor Details
This class inherits a constructor from Faraday::Adapter
Instance Method Details
#call(env) ⇒ Object
9 10 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 |
# File 'lib/faraday/adapter/excon.rb', line 9 def call(env) super opts = opts_from_env(env) conn = create_connection(env, opts) req_opts = { method: env[:method].to_s.upcase, headers: env[:request_headers], body: read_body(env) } req = env[:request] if req&.stream_response? total = 0 req_opts[:response_block] = lambda do |chunk, _remain, _total| req.on_data.call(chunk, total += chunk.size) end end resp = conn.request(req_opts) save_response(env, resp.status.to_i, resp.body, resp.headers, resp.reason_phrase) @app.call(env) rescue ::Excon::Errors::SocketError => e raise Faraday::TimeoutError, e if e. =~ /\btimeout\b/ raise Faraday::SSLError, e if e. =~ /\bcertificate\b/ raise Faraday::ConnectionFailed, e rescue ::Excon::Errors::Timeout => e raise Faraday::TimeoutError, e end |
#create_connection(env, opts) ⇒ Excon
45 46 47 |
# File 'lib/faraday/adapter/excon.rb', line 45 def create_connection(env, opts) ::Excon.new(env[:url].to_s, opts.merge(@connection_options)) end |
#read_body(env) ⇒ Object
TODO: support streaming requests
50 51 52 |
# File 'lib/faraday/adapter/excon.rb', line 50 def read_body(env) env[:body].respond_to?(:read) ? env[:body].read : env[:body] end |