From e27df4e9151707aad10e08e05a87cb666d03bd84 Mon Sep 17 00:00:00 2001 From: Dan Dofter Date: Tue, 8 May 2012 19:08:14 -0700 Subject: [PATCH] set excon timeouts from faraday configuration and handle timeout errors --- lib/faraday/adapter/excon.rb | 16 ++++++++++++++++ test/adapters/excon_test.rb | 3 --- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/faraday/adapter/excon.rb b/lib/faraday/adapter/excon.rb index 5f10b65f..8be4126e 100644 --- a/lib/faraday/adapter/excon.rb +++ b/lib/faraday/adapter/excon.rb @@ -11,6 +11,20 @@ module Faraday opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true) opts[:ssl_ca_path] = ssl[:ca_file] if ssl[:ca_file] end + + if ( req = env[:request] ) + if req[:timeout] + opts[:read_timeout] = req[:timeout] + opts[:connect_timeout] = req[:timeout] + opts[:write_timeout] = req[:timeout] + end + + if req[:open_timeout] + opts[:connect_timeout] = req[:open_timeout] + opts[:write_timeout] = req[:open_timeout] + end + end + conn = ::Excon.new(env[:url].to_s, opts) resp = conn.request \ @@ -23,6 +37,8 @@ module Faraday @app.call env rescue ::Excon::Errors::SocketError raise Error::ConnectionFailed, $! + rescue ::Excon::Errors::Timeout => err + raise Faraday::Error::TimeoutError, err end end end diff --git a/test/adapters/excon_test.rb b/test/adapters/excon_test.rb index 2ab8a46c..9c2358db 100644 --- a/test/adapters/excon_test.rb +++ b/test/adapters/excon_test.rb @@ -10,9 +10,6 @@ module Adapters warn "Warning: Skipping Excon tests on Rubinius" else Integration.apply(self, :NonParallel) do - # https://github.com/eventmachine/eventmachine/pull/289 - undef :test_timeout - # FIXME: this test fails on Travis with # "Faraday::Error::ClientError: the server responded with status 400" undef :test_POST_sends_files if ENV['CI']