Permalink
Browse files

experimental excon support

  • Loading branch information...
1 parent da851ef commit d9a1be15e91f302e1cc3193dfce94582eaae7c34 @technoweenie technoweenie committed Feb 13, 2011
Showing with 44 additions and 1 deletion.
  1. +3 −1 lib/faraday/adapter.rb
  2. +41 −0 lib/faraday/adapter/excon.rb
View
4 lib/faraday/adapter.rb
@@ -12,6 +12,7 @@ class Adapter < Middleware
:Typhoeus => 'typhoeus',
:EMSynchrony => 'em_synchrony',
:Patron => 'patron',
+ :Excon => 'excon',
:Test => 'test'
register_lookup_modules \
@@ -20,7 +21,8 @@ class Adapter < Middleware
:net_http => :NetHttp,
:typhoeus => :Typhoeus,
:patron => :Patron,
- :em_synchrony => :EMSynchrony
+ :em_synchrony => :EMSynchrony,
+ :excon => :Excon
def call(env)
process_body_for_request(env)
View
41 lib/faraday/adapter/excon.rb
@@ -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

0 comments on commit d9a1be1

Please sign in to comment.