Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

experimental excon support

  • Loading branch information...
commit d9a1be15e91f302e1cc3193dfce94582eaae7c34 1 parent da851ef
risk danger olson authored February 13, 2011
4  lib/faraday/adapter.rb
@@ -12,6 +12,7 @@ class Adapter < Middleware
12 12
       :Typhoeus       => 'typhoeus',
13 13
       :EMSynchrony    => 'em_synchrony',
14 14
       :Patron         => 'patron',
  15
+      :Excon          => 'excon',
15 16
       :Test           => 'test'
16 17
 
17 18
     register_lookup_modules \
@@ -20,7 +21,8 @@ class Adapter < Middleware
20 21
       :net_http        => :NetHttp,
21 22
       :typhoeus        => :Typhoeus,
22 23
       :patron          => :Patron,
23  
-      :em_synchrony    => :EMSynchrony
  24
+      :em_synchrony    => :EMSynchrony,
  25
+      :excon           => :Excon
24 26
 
25 27
     def call(env)
26 28
       process_body_for_request(env)
41  lib/faraday/adapter/excon.rb
... ...
@@ -0,0 +1,41 @@
  1
+module Faraday
  2
+  class Adapter
  3
+    class Excon < Faraday::Adapter
  4
+      begin
  5
+        require 'excon'
  6
+      rescue LoadError, NameError => e
  7
+        self.load_error = e
  8
+      end
  9
+
  10
+      def call(env)
  11
+        super
  12
+
  13
+        conn = ::Excon.new(env[:url].to_s)
  14
+        if ssl = (env[:url].scheme == 'https' && env[:ssl])
  15
+          ::Excon.ssl_verify_peer = !!ssl[:verify] if ssl.key?(:verify)
  16
+          if ca_file = ssl[:ca_file]
  17
+            ::Excon.ssl_ca_path = ca_file
  18
+          end
  19
+        end
  20
+
  21
+        resp = conn.request \
  22
+          :method  => env[:method].to_s.upcase,
  23
+          :headers => env[:request_headers],
  24
+          :body    => env[:body]
  25
+
  26
+        env.update \
  27
+          :status => resp.status.to_i,
  28
+          :response_headers => {},
  29
+          :body => resp.body
  30
+
  31
+        resp.headers.each do |key, value|
  32
+          env[:response_headers][key.downcase] = value
  33
+        end
  34
+
  35
+        @app.call env
  36
+      rescue ::Excon::Errors::SocketError => e
  37
+        raise Error::ConnectionFailed.new(e)
  38
+      end
  39
+    end
  40
+  end
  41
+end

0 notes on commit d9a1be1

Please sign in to comment.
Something went wrong with that request. Please try again.