mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
experimental excon support
This commit is contained in:
parent
da851efb64
commit
d9a1be15e9
@ -12,6 +12,7 @@ module Faraday
|
|||||||
:Typhoeus => 'typhoeus',
|
:Typhoeus => 'typhoeus',
|
||||||
:EMSynchrony => 'em_synchrony',
|
:EMSynchrony => 'em_synchrony',
|
||||||
:Patron => 'patron',
|
:Patron => 'patron',
|
||||||
|
:Excon => 'excon',
|
||||||
:Test => 'test'
|
:Test => 'test'
|
||||||
|
|
||||||
register_lookup_modules \
|
register_lookup_modules \
|
||||||
@ -20,7 +21,8 @@ module Faraday
|
|||||||
:net_http => :NetHttp,
|
:net_http => :NetHttp,
|
||||||
:typhoeus => :Typhoeus,
|
:typhoeus => :Typhoeus,
|
||||||
:patron => :Patron,
|
:patron => :Patron,
|
||||||
:em_synchrony => :EMSynchrony
|
:em_synchrony => :EMSynchrony,
|
||||||
|
:excon => :Excon
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
process_body_for_request(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