From c1ea5fc212ca1c8f4ec7b05ab9c521b35c812326 Mon Sep 17 00:00:00 2001 From: Abdul Chaudhry Date: Thu, 17 Feb 2011 10:55:48 -0800 Subject: [PATCH] net http timeout can also be a float --- lib/httparty.rb | 2 +- lib/httparty/request.rb | 2 +- spec/httparty_spec.rb | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/httparty.rb b/lib/httparty.rb index 5e4dfc27..05dbdc17 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -152,7 +152,7 @@ def default_params(h={}) # default_timeout 10 # end def default_timeout(t) - raise ArgumentError, 'Timeout must be an integer' unless t && t.is_a?(Integer) + raise ArgumentError, 'Timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float)) default_options[:timeout] = t end diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index c7e90538..1f8b78b5 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -101,7 +101,7 @@ def http http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport]) http.use_ssl = ssl_implied? - if options[:timeout] && options[:timeout].is_a?(Integer) + if options[:timeout] && (options[:timeout].is_a?(Integer) || options[:timeout].is_a?(Float)) http.open_timeout = options[:timeout] http.read_timeout = options[:timeout] end diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index d39dee65..f601d2af 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -232,6 +232,11 @@ def second_method @klass.default_timeout 10 @klass.default_options[:timeout].should == 10 end + + it "should support floats" do + @klass.default_timeout 0.5 + @klass.default_options[:timeout].should == 0.5 + end end describe "debug_output" do