aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-08-09 02:24:35 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-09 02:28:00 -0700
commita0caad5255ed120192755fce10960a38b53c056d (patch)
treedae41870052979a9bbbe42c9897a9db6fe46e562 /activeresource
parent60219a13da9899b97f9b2ff4ecb7a9508aeea662 (diff)
downloadrails-a0caad5255ed120192755fce10960a38b53c056d.tar.gz
rails-a0caad5255ed120192755fce10960a38b53c056d.tar.bz2
rails-a0caad5255ed120192755fce10960a38b53c056d.zip
Setting connection timeout also affects Net::HTTP open_timeout.
[#2947 state:resolved]
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/connection.rb26
-rw-r--r--activeresource/test/connection_test.rb11
2 files changed, 30 insertions, 7 deletions
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index b29e379c53..ef57c1f8b2 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -137,15 +137,27 @@ module ActiveResource
# Creates new Net::HTTP instance for communication with the
# remote service and resources.
def http
- http =
- if @proxy
- Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
- else
- Net::HTTP.new(@site.host, @site.port)
- end
+ configure_http(new_http)
+ end
+
+ def new_http
+ if @proxy
+ Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
+ else
+ Net::HTTP.new(@site.host, @site.port)
+ end
+ end
+
+ def configure_http(http)
http.use_ssl = @site.is_a?(URI::HTTPS)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
- http.read_timeout = @timeout if @timeout # If timeout is not set, the default Net::HTTP timeout (60s) is used.
+
+ # Net::HTTP timeouts default to 60 seconds.
+ if @timeout
+ http.open_timeout = @timeout
+ http.read_timeout = @timeout
+ end
+
http
end
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 60a8204533..12e8058b0c 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -185,6 +185,17 @@ class ConnectionTest < Test::Unit::TestCase
assert_raise(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') }
end
+ def test_setting_timeout
+ http = Net::HTTP.new('')
+
+ [10, 20].each do |timeout|
+ @conn.timeout = timeout
+ @conn.send(:configure_http, http)
+ assert_equal timeout, http.open_timeout
+ assert_equal timeout, http.read_timeout
+ end
+ end
+
def test_accept_http_header
@http = mock('new Net::HTTP')
@conn.expects(:http).returns(@http)