Skip to content

Commit

Permalink
Support read and open timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed May 19, 2010
1 parent 4e1ca72 commit a94fcac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion History.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
=== 1.1
=== 1.2

* Minor Enhancements
* Net::HTTP#read_timeout is now supported
* Net::HTTP#open_timeout is now supported

=== 1.1 / 2010-05-18

* Minor Enhancements
* Proxy support, see Net::HTTP::Persistent::new,
Expand Down
14 changes: 14 additions & 0 deletions lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class Error < StandardError; end

attr_reader :name

##
# Seconds to wait until a connection is opened. See Net::HTTP#open_timeout

attr_accessor :open_timeout

##
# This client's SSL private key

Expand All @@ -101,6 +106,11 @@ class Error < StandardError; end

attr_reader :proxy_uri

##
# Seconds to wait until reading one block. See Net::HTTP#read_timeout

attr_accessor :read_timeout

##
# Where this instance's request counts live in the thread local variables

Expand Down Expand Up @@ -160,6 +170,8 @@ def initialize name = nil, proxy = nil
@debug_output = nil
@headers = {}
@keep_alive = 30
@open_timeout = nil
@read_timeout = nil

key = ['net_http_persistent', name, 'connections'].compact.join '_'
@connection_key = key.intern
Expand Down Expand Up @@ -193,6 +205,8 @@ def connection_for uri

unless connection.started? then
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

ssl connection if uri.scheme == 'https'

Expand Down
5 changes: 5 additions & 0 deletions test/test_net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ def test_initialize_uri
end

def test_connection_for
@http.open_timeout = 123
@http.read_timeout = 321
c = @http.connection_for @uri

assert c.started?
refute c.proxy?

assert_equal 123, c.open_timeout
assert_equal 321, c.read_timeout

assert_includes conns.keys, 'example.com:80'
assert_same c, conns['example.com:80']
end
Expand Down

0 comments on commit a94fcac

Please sign in to comment.