Permalink
Browse files

Set the read_timeout for every connection. Fixes #33

  • Loading branch information...
1 parent 9fc2681 commit 2dd5f8bbf65902de36bb127d4a5a702de4e1ed63 @drbrain committed Oct 18, 2012
Showing with 8 additions and 3 deletions.
  1. +2 −0 History.txt
  2. +2 −1 lib/net/http/persistent.rb
  3. +4 −2 test/test_net_http_persistent.rb
View
@@ -3,6 +3,8 @@
* Minor enhancements
* Added Net::HTTP::Persistent::detect_idle_timeout which can be used to
determine the idle timeout for a host.
+ * The read timeout may now be updated for every request. Issue #33 by
+ Mislav Marohnić
* Added NO_PROXY support. Pull Request #31 by Laurence Rowe.
* Added #cert and #key aliases for Net::HTTP compatibility. Pull request
#26 by dlee.
@@ -569,6 +569,8 @@ def connection_for uri
start connection unless connection.started?
+ connection.read_timeout = @read_timeout if @read_timeout
+
connection
rescue Errno::ECONNREFUSED
address = connection.proxy_address || connection.address
@@ -622,7 +624,6 @@ def expired? connection
def start connection
connection.set_debug_output @debug_output if @debug_output
connection.open_timeout = @open_timeout if @open_timeout
- connection.read_timeout = @read_timeout if @read_timeout
connection.start
@@ -253,10 +253,14 @@ def test_connection_for_cached
cached.start
conns[0]['example.com:80'] = cached
+ @http.read_timeout = 5
+
c = @http.connection_for @uri
assert c.started?
+ assert_equal 5, c.read_timeout
+
assert_same cached, c
end
@@ -1453,13 +1457,11 @@ def test_start
@http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
@http.debug_output = $stderr
- @http.read_timeout = 5
@http.open_timeout = 6
@http.start c
assert_equal $stderr, c.debug_output
- assert_equal 5, c.read_timeout
assert_equal 6, c.open_timeout
socket = c.instance_variable_get :@socket

0 comments on commit 2dd5f8b

Please sign in to comment.