From a5a398c2319bece0b00bd1a5e02f54929b8677e2 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 19 Sep 2019 15:50:50 -0600 Subject: [PATCH] teach Excon to use #fetch_timeout --- lib/faraday/adapter/excon.rb | 20 +++++++++----------- spec/faraday/adapter/excon_spec.rb | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/faraday/adapter/excon.rb b/lib/faraday/adapter/excon.rb index b0ea0d7d..03be734d 100644 --- a/lib/faraday/adapter/excon.rb +++ b/lib/faraday/adapter/excon.rb @@ -90,17 +90,15 @@ module Faraday end def amend_opts_with_timeouts!(opts, req) - timeout = req[:timeout] - return unless timeout - - opts[:read_timeout] = timeout - opts[:connect_timeout] = timeout - opts[:write_timeout] = timeout - - open_timeout = req[:open_timeout] - return unless open_timeout - - opts[:connect_timeout] = open_timeout + if sec = req.fetch_timeout(:read) + opts[:read_timeout] = sec + end + if sec = req.fetch_timeout(:write) + opts[:write_timeout] = sec + end + if sec = req.fetch_timeout(:open) + opts[:connect_timeout] = sec + end end def amend_opts_with_proxy_settings!(opts, req) diff --git a/spec/faraday/adapter/excon_spec.rb b/spec/faraday/adapter/excon_spec.rb index e08df06b..b5064a6b 100644 --- a/spec/faraday/adapter/excon_spec.rb +++ b/spec/faraday/adapter/excon_spec.rb @@ -43,7 +43,7 @@ RSpec.describe Faraday::Adapter::Excon do options = adapter.send(:opts_from_env, env) expect(options[:read_timeout]).to eq(nil) expect(options[:write_timeout]).to eq(nil) - expect(options[:connect_timeout]).to eq(nil) + expect(options[:connect_timeout]).to eq(3) end end end