mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-07 00:11:11 -04:00
experimental excon support
This commit is contained in:
parent
da851efb64
commit
d9a1be15e9
@ -12,6 +12,7 @@ module Faraday
|
||||
:Typhoeus => 'typhoeus',
|
||||
:EMSynchrony => 'em_synchrony',
|
||||
:Patron => 'patron',
|
||||
:Excon => 'excon',
|
||||
:Test => 'test'
|
||||
|
||||
register_lookup_modules \
|
||||
@ -20,7 +21,8 @@ module Faraday
|
||||
:net_http => :NetHttp,
|
||||
:typhoeus => :Typhoeus,
|
||||
:patron => :Patron,
|
||||
:em_synchrony => :EMSynchrony
|
||||
:em_synchrony => :EMSynchrony,
|
||||
:excon => :Excon
|
||||
|
||||
def call(env)
|
||||
process_body_for_request(env)
|
||||
|
41
lib/faraday/adapter/excon.rb
Normal file
41
lib/faraday/adapter/excon.rb
Normal file
@ -0,0 +1,41 @@
|
||||
module Faraday
|
||||
class Adapter
|
||||
class Excon < Faraday::Adapter
|
||||
begin
|
||||
require 'excon'
|
||||
rescue LoadError, NameError => e
|
||||
self.load_error = e
|
||||
end
|
||||
|
||||
def call(env)
|
||||
super
|
||||
|
||||
conn = ::Excon.new(env[:url].to_s)
|
||||
if ssl = (env[:url].scheme == 'https' && env[:ssl])
|
||||
::Excon.ssl_verify_peer = !!ssl[:verify] if ssl.key?(:verify)
|
||||
if ca_file = ssl[:ca_file]
|
||||
::Excon.ssl_ca_path = ca_file
|
||||
end
|
||||
end
|
||||
|
||||
resp = conn.request \
|
||||
:method => env[:method].to_s.upcase,
|
||||
:headers => env[:request_headers],
|
||||
:body => env[:body]
|
||||
|
||||
env.update \
|
||||
:status => resp.status.to_i,
|
||||
:response_headers => {},
|
||||
:body => resp.body
|
||||
|
||||
resp.headers.each do |key, value|
|
||||
env[:response_headers][key.downcase] = value
|
||||
end
|
||||
|
||||
@app.call env
|
||||
rescue ::Excon::Errors::SocketError => e
|
||||
raise Error::ConnectionFailed.new(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user