mirror of
https://github.com/lostisland/faraday.git
synced 2025-11-22 00:08:56 -05:00
Refactor excon adapter to use #connection
This commit is contained in:
parent
36ff4a5c3e
commit
86d3cf2e8b
@ -6,15 +6,19 @@ module Faraday
|
||||
class Excon < Faraday::Adapter
|
||||
dependency 'excon'
|
||||
|
||||
def build_connection(env)
|
||||
opts = opts_from_env(env)
|
||||
::Excon.new(env[:url].to_s, opts.merge(@connection_options))
|
||||
end
|
||||
|
||||
def call(env)
|
||||
super
|
||||
|
||||
opts = opts_from_env(env)
|
||||
conn = create_connection(env, opts)
|
||||
|
||||
resp = conn.request(method: env[:method].to_s.upcase,
|
||||
headers: env[:request_headers],
|
||||
body: read_body(env))
|
||||
resp = connection(env) do |http|
|
||||
http.request(method: env[:method].to_s.upcase,
|
||||
headers: env[:request_headers],
|
||||
body: read_body(env))
|
||||
end
|
||||
|
||||
req = env[:request]
|
||||
if req&.stream_response?
|
||||
@ -36,11 +40,6 @@ module Faraday
|
||||
raise Faraday::TimeoutError, e
|
||||
end
|
||||
|
||||
# @return [Excon]
|
||||
def create_connection(env, opts)
|
||||
::Excon.new(env[:url].to_s, opts.merge(@connection_options))
|
||||
end
|
||||
|
||||
# TODO: support streaming requests
|
||||
def read_body(env)
|
||||
env[:body].respond_to?(:read) ? env[:body].read : env[:body]
|
||||
|
||||
@ -10,7 +10,7 @@ RSpec.describe Faraday::Adapter::Excon do
|
||||
|
||||
adapter = described_class.new(nil, debug_request: true)
|
||||
|
||||
conn = adapter.create_connection({ url: url }, {})
|
||||
conn = adapter.build_connection(url: url)
|
||||
|
||||
expect(conn.data[:debug_request]).to be_truthy
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user