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 collapse
- OPTS_KEYS =
[ %i[ciphers ciphers], %i[client_cert client_cert], %i[client_key client_key], %i[certificate certificate], %i[private_key private_key], %i[ssl_ca_path ca_path], %i[ssl_ca_file ca_file], %i[ssl_version version], %i[ssl_min_version min_version], %i[ssl_max_version max_version] ].freeze
Instance Method Summary collapse
- #build_connection(env) ⇒ Object
- #call(env) ⇒ Object
-
#read_body(env) ⇒ Object
TODO: support streaming requests.
Instance Method Details
#build_connection(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/faraday/adapter/excon.rb', line 20 def build_connection(env) return @connection if @connection_options[:persistent] && defined?(@connection) opts = opts_from_env(env) # remove path & query, because persistent can re-use connection url = env[:url].dup url.path = '' url.query = nil @connection = ::Excon.new(url.to_s, opts.merge(@connection_options)) end |
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/faraday/adapter/excon.rb', line 33 def call(env) super req_opts = { path: env[:url].path, query: env[:url].query, method: env[:method].to_s.upcase, headers: env[:request_headers], body: read_body(env) } req = env[:request] yielded = false if env.stream_response? total = 0 req_opts[:response_block] = lambda do |chunk, _remain, _total| yielded = true req.on_data.call(chunk, total += chunk.bytesize, env) end end resp = connect_and_request(env, req_opts) # duplicate env.stream_response helper behavior for empty streams req.on_data.call(+'', 0, env) if req&.stream_response? && !yielded save_response(env, resp.status.to_i, resp.body, resp.headers, resp.reason_phrase) @app.call(env) end |
#read_body(env) ⇒ Object
TODO: support streaming requests
65 66 67 |
# File 'lib/faraday/adapter/excon.rb', line 65 def read_body(env) env[:body].respond_to?(:read) ? env[:body].read : env[:body] end |