net-http-persistent 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,4 +1,11 @@
1
- === 1.1
1
+ === 1.2 / 2010-05-20
2
+
3
+ * Minor Enhancements
4
+ * Net::HTTP#read_timeout is now supported
5
+ * Net::HTTP#open_timeout is now supported
6
+ * Net::HTTP::Persistent#request now supports a block like Net::HTTP#request
7
+
8
+ === 1.1 / 2010-05-18
2
9
 
3
10
  * Minor Enhancements
4
11
  * Proxy support, see Net::HTTP::Persistent::new,
@@ -36,7 +36,7 @@ class Net::HTTP::Persistent
36
36
  ##
37
37
  # The version of Net::HTTP::Persistent use are using
38
38
 
39
- VERSION = '1.1'
39
+ VERSION = '1.2'
40
40
 
41
41
  ##
42
42
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -91,6 +91,11 @@ class Net::HTTP::Persistent
91
91
 
92
92
  attr_reader :name
93
93
 
94
+ ##
95
+ # Seconds to wait until a connection is opened. See Net::HTTP#open_timeout
96
+
97
+ attr_accessor :open_timeout
98
+
94
99
  ##
95
100
  # This client's SSL private key
96
101
 
@@ -101,6 +106,11 @@ class Net::HTTP::Persistent
101
106
 
102
107
  attr_reader :proxy_uri
103
108
 
109
+ ##
110
+ # Seconds to wait until reading one block. See Net::HTTP#read_timeout
111
+
112
+ attr_accessor :read_timeout
113
+
104
114
  ##
105
115
  # Where this instance's request counts live in the thread local variables
106
116
 
@@ -160,6 +170,8 @@ class Net::HTTP::Persistent
160
170
  @debug_output = nil
161
171
  @headers = {}
162
172
  @keep_alive = 30
173
+ @open_timeout = nil
174
+ @read_timeout = nil
163
175
 
164
176
  key = ['net_http_persistent', name, 'connections'].compact.join '_'
165
177
  @connection_key = key.intern
@@ -193,6 +205,8 @@ class Net::HTTP::Persistent
193
205
 
194
206
  unless connection.started? then
195
207
  connection.set_debug_output @debug_output if @debug_output
208
+ connection.open_timeout = @open_timeout if @open_timeout
209
+ connection.read_timeout = @read_timeout if @read_timeout
196
210
 
197
211
  ssl connection if uri.scheme == 'https'
198
212
 
@@ -289,12 +303,15 @@ class Net::HTTP::Persistent
289
303
  # Makes a request on +uri+. If +req+ is nil a Net::HTTP::Get is performed
290
304
  # against +uri+.
291
305
  #
306
+ # If a block is passed #request behaves like Net::HTTP#request (the body of
307
+ # the response will not have been read).
308
+ #
292
309
  # +req+ must be a Net::HTTPRequest subclass (see Net::HTTP for a list).
293
310
  #
294
311
  # If there is an error and the request is idempontent according to RFC 2616
295
312
  # it will be retried automatically.
296
313
 
297
- def request uri, req = nil
314
+ def request uri, req = nil, &block
298
315
  Thread.current[@request_key] ||= Hash.new 0
299
316
  retried = false
300
317
  bad_response = false
@@ -313,7 +330,7 @@ class Net::HTTP::Persistent
313
330
 
314
331
  begin
315
332
  count = Thread.current[@request_key][connection_id] += 1
316
- response = connection.request req
333
+ response = connection.request req, &block
317
334
 
318
335
  rescue Net::HTTPBadResponse => e
319
336
  message = error_message connection
@@ -32,7 +32,13 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
32
32
  c = Object.new
33
33
  # Net::HTTP
34
34
  def c.finish; @finished = true end
35
- def c.request(req) @req = req; :response end
35
+ def c.request(req)
36
+ @req = req
37
+ r = Object.new
38
+ def r.read_body() :read_body end
39
+ yield r if block_given?
40
+ :response
41
+ end
36
42
  def c.reset; @reset = true end
37
43
  def c.start; end
38
44
 
@@ -78,11 +84,16 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
78
84
  end
79
85
 
80
86
  def test_connection_for
87
+ @http.open_timeout = 123
88
+ @http.read_timeout = 321
81
89
  c = @http.connection_for @uri
82
90
 
83
91
  assert c.started?
84
92
  refute c.proxy?
85
93
 
94
+ assert_equal 123, c.open_timeout
95
+ assert_equal 321, c.read_timeout
96
+
86
97
  assert_includes conns.keys, 'example.com:80'
87
98
  assert_same c, conns['example.com:80']
88
99
  end
@@ -333,6 +344,29 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
333
344
  assert_match %r%too many bad responses%, e.message
334
345
  end
335
346
 
347
+ def test_request_block
348
+ @http.headers['user-agent'] = 'test ua'
349
+ c = connection
350
+ body = nil
351
+
352
+ res = @http.request @uri do |r|
353
+ body = r.read_body
354
+ end
355
+
356
+ req = c.req
357
+
358
+ assert_equal :response, res
359
+ refute_nil body
360
+
361
+ assert_kind_of Net::HTTP::Get, req
362
+ assert_equal '/path', req.path
363
+ assert_equal 'keep-alive', req['connection']
364
+ assert_equal '30', req['keep-alive']
365
+ assert_match %r%test ua%, req['user-agent']
366
+
367
+ assert_equal 1, reqs[c.object_id]
368
+ end
369
+
336
370
  def test_request_reset
337
371
  c = connection
338
372
  def c.request(*a) raise Errno::ECONNRESET end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-persistent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
9
- version: "1.1"
8
+ - 2
9
+ version: "1.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eric Hodel
@@ -35,7 +35,7 @@ cert_chain:
35
35
  x52qPcexcYZR7w==
36
36
  -----END CERTIFICATE-----
37
37
 
38
- date: 2010-05-18 00:00:00 -07:00
38
+ date: 2010-05-20 00:00:00 -07:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file