experimental excon support

This commit is contained in:
rick 2011-02-13 14:27:41 -08:00
parent da851efb64
commit d9a1be15e9
2 changed files with 44 additions and 1 deletions

View File

@ -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)

View 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