net-http-persistent 1.2.5 → 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +2 -1
- data/History.txt +8 -0
- data/lib/net/http/persistent.rb +29 -9
- data/test/test_net_http_persistent.rb +69 -34
- metadata +15 -32
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
)�9���ϬT\4V���I�i)n``]�M+(>kN٣$2ע�7����<H�r�|5��������I�Y8��2�-
|
2
|
+
[S��Z��͑���Le�J��74K�o/*ͼ��-���%���v���}��Q�1R�u�s�,X#��j�7�����̍������{6�:H�B���$:�0z4��6{ͮ"�����c��{�I�#���J�NyA�:��;^��wU����-H����ܡ�C�g:X��������f�n9\��lC�I
|
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 1.3 / 2010-09-08
|
2
|
+
|
3
|
+
* Minor Enhancements
|
4
|
+
* HTTP versions are now recorded. This information is not currently used.
|
5
|
+
|
6
|
+
* Bug Fixes
|
7
|
+
* #shutdown no longer fails when an unstarted HTTP connection is shut down.
|
8
|
+
|
1
9
|
=== 1.2.5 / 2010-07-27
|
2
10
|
|
3
11
|
* Bug Fixes
|
data/lib/net/http/persistent.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'net/http/faster'
|
3
3
|
require 'uri'
|
4
|
+
require 'cgi' # for escaping
|
4
5
|
|
5
6
|
##
|
6
7
|
# Persistent connections for Net::HTTP
|
@@ -36,7 +37,7 @@ class Net::HTTP::Persistent
|
|
36
37
|
##
|
37
38
|
# The version of Net::HTTP::Persistent use are using
|
38
39
|
|
39
|
-
VERSION = '1.
|
40
|
+
VERSION = '1.3'
|
40
41
|
|
41
42
|
##
|
42
43
|
# Error class for errors raised by Net::HTTP::Persistent. Various
|
@@ -74,6 +75,12 @@ class Net::HTTP::Persistent
|
|
74
75
|
|
75
76
|
attr_reader :headers
|
76
77
|
|
78
|
+
##
|
79
|
+
# Maps host:port to an HTTP version. This allows us to enable version
|
80
|
+
# specific features.
|
81
|
+
|
82
|
+
attr_reader :http_versions
|
83
|
+
|
77
84
|
##
|
78
85
|
# The value sent in the Keep-Alive header. Defaults to 30. Not needed for
|
79
86
|
# HTTP/1.1 servers.
|
@@ -167,11 +174,12 @@ class Net::HTTP::Persistent
|
|
167
174
|
@proxy_connection_id = [nil, *@proxy_args].join ':'
|
168
175
|
end
|
169
176
|
|
170
|
-
@debug_output
|
171
|
-
@headers
|
172
|
-
@
|
173
|
-
@
|
174
|
-
@
|
177
|
+
@debug_output = nil
|
178
|
+
@headers = {}
|
179
|
+
@http_versions = {}
|
180
|
+
@keep_alive = 30
|
181
|
+
@open_timeout = nil
|
182
|
+
@read_timeout = nil
|
175
183
|
|
176
184
|
key = ['net_http_persistent', name, 'connections'].compact.join '_'
|
177
185
|
@connection_key = key.intern
|
@@ -235,7 +243,7 @@ class Net::HTTP::Persistent
|
|
235
243
|
# URI::escape wrapper
|
236
244
|
|
237
245
|
def escape str
|
238
|
-
|
246
|
+
CGI.escape str if str
|
239
247
|
end
|
240
248
|
|
241
249
|
##
|
@@ -248,6 +256,13 @@ class Net::HTTP::Persistent
|
|
248
256
|
rescue IOError
|
249
257
|
end
|
250
258
|
|
259
|
+
##
|
260
|
+
# Returns the HTTP protocol version for +uri+
|
261
|
+
|
262
|
+
def http_version uri
|
263
|
+
@http_versions["#{uri.host}:#{uri.port}"]
|
264
|
+
end
|
265
|
+
|
251
266
|
##
|
252
267
|
# Is +req+ idempotent according to RFC 2616?
|
253
268
|
|
@@ -338,7 +353,7 @@ class Net::HTTP::Persistent
|
|
338
353
|
connection_id = connection.object_id
|
339
354
|
|
340
355
|
begin
|
341
|
-
|
356
|
+
Thread.current[@request_key][connection_id] += 1
|
342
357
|
response = connection.request req, &block
|
343
358
|
|
344
359
|
rescue Net::HTTPBadResponse => e
|
@@ -365,6 +380,8 @@ class Net::HTTP::Persistent
|
|
365
380
|
retry
|
366
381
|
end
|
367
382
|
|
383
|
+
@http_versions["#{uri.host}:#{uri.port}"] ||= response.http_version
|
384
|
+
|
368
385
|
response
|
369
386
|
end
|
370
387
|
|
@@ -378,7 +395,10 @@ class Net::HTTP::Persistent
|
|
378
395
|
connections = Thread.current[@connection_key]
|
379
396
|
|
380
397
|
connections.each do |_, connection|
|
381
|
-
|
398
|
+
begin
|
399
|
+
connection.finish
|
400
|
+
rescue IOError
|
401
|
+
end
|
382
402
|
end if connections
|
383
403
|
|
384
404
|
Thread.current[@connection_key] = nil
|
@@ -4,6 +4,8 @@ require 'openssl'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class Net::HTTP
|
7
|
+
alias orig_connect connect
|
8
|
+
|
7
9
|
def connect
|
8
10
|
end
|
9
11
|
end
|
@@ -28,29 +30,40 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
33
|
+
def basic_connection
|
32
34
|
c = Object.new
|
33
|
-
|
35
|
+
c.instance_variable_set :@finished, false
|
36
|
+
c.instance_variable_set :@reset, false
|
37
|
+
c.instance_variable_set :@started, false
|
38
|
+
|
34
39
|
def c.finish; @finished = true 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
|
42
40
|
def c.reset; @reset = true end
|
43
41
|
def c.start; end
|
44
42
|
|
45
|
-
# util
|
46
43
|
def c.req() @req; end
|
47
44
|
def c.reset?; @reset end
|
48
45
|
def c.started?; true end
|
49
46
|
def c.finished?; @finished end
|
47
|
+
|
50
48
|
conns["#{@uri.host}:#{@uri.port}"] = c
|
51
49
|
c
|
52
50
|
end
|
53
51
|
|
52
|
+
def connection
|
53
|
+
c = basic_connection
|
54
|
+
|
55
|
+
def c.request(req)
|
56
|
+
@req = req
|
57
|
+
r = Net::HTTPResponse.allocate
|
58
|
+
def r.http_version() '1.1' end
|
59
|
+
def r.read_body() :read_body end
|
60
|
+
yield r if block_given?
|
61
|
+
r
|
62
|
+
end
|
63
|
+
|
64
|
+
c
|
65
|
+
end
|
66
|
+
|
54
67
|
def conns
|
55
68
|
Thread.current[@http.connection_key] ||= {}
|
56
69
|
end
|
@@ -191,11 +204,12 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
191
204
|
def test_escape
|
192
205
|
assert_nil @http.escape nil
|
193
206
|
|
194
|
-
assert_equal '
|
207
|
+
assert_equal '+%3F', @http.escape(' ?')
|
195
208
|
end
|
196
209
|
|
197
210
|
def test_finish
|
198
211
|
c = Object.new
|
212
|
+
c.instance_variable_set :@started, false
|
199
213
|
def c.finish; @finished = true end
|
200
214
|
def c.finished?; @finished end
|
201
215
|
def c.start; @started = true end
|
@@ -211,6 +225,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
211
225
|
|
212
226
|
def test_finish_io_error
|
213
227
|
c = Object.new
|
228
|
+
c.instance_variable_set :@started, false
|
214
229
|
def c.finish; @finished = true; raise IOError end
|
215
230
|
def c.finished?; @finished end
|
216
231
|
def c.start; @started = true end
|
@@ -223,6 +238,16 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
223
238
|
assert c.finished?
|
224
239
|
end
|
225
240
|
|
241
|
+
def test_http_version
|
242
|
+
assert_nil @http.http_version @uri
|
243
|
+
|
244
|
+
connection
|
245
|
+
|
246
|
+
@http.request @uri
|
247
|
+
|
248
|
+
assert_equal '1.1', @http.http_version(@uri)
|
249
|
+
end
|
250
|
+
|
226
251
|
def test_idempotent_eh
|
227
252
|
assert @http.idempotent? Net::HTTP::Delete.new '/'
|
228
253
|
assert @http.idempotent? Net::HTTP::Get.new '/'
|
@@ -346,7 +371,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
346
371
|
res = @http.request @uri
|
347
372
|
req = c.req
|
348
373
|
|
349
|
-
|
374
|
+
assert_kind_of Net::HTTPResponse, res
|
350
375
|
|
351
376
|
assert_kind_of Net::HTTP::Get, req
|
352
377
|
assert_equal '/path', req.path
|
@@ -358,7 +383,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
358
383
|
end
|
359
384
|
|
360
385
|
def test_request_bad_response
|
361
|
-
c =
|
386
|
+
c = basic_connection
|
362
387
|
def c.request(*a) raise Net::HTTPBadResponse end
|
363
388
|
|
364
389
|
e = assert_raises Net::HTTP::Persistent::Error do
|
@@ -370,23 +395,23 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
370
395
|
end
|
371
396
|
|
372
397
|
def test_request_bad_response_retry
|
373
|
-
c =
|
398
|
+
c = basic_connection
|
374
399
|
def c.request(*a)
|
375
|
-
|
376
|
-
|
400
|
+
if defined? @called then
|
401
|
+
Net::HTTPResponse.allocate
|
402
|
+
else
|
403
|
+
@called = true
|
404
|
+
raise Net::HTTPBadResponse
|
377
405
|
end
|
378
|
-
|
379
|
-
raise Net::HTTPBadResponse
|
380
406
|
end
|
381
407
|
|
382
|
-
|
408
|
+
@http.request @uri
|
383
409
|
|
384
|
-
assert_equal :response, res
|
385
410
|
assert c.finished?
|
386
411
|
end
|
387
412
|
|
388
413
|
def test_request_bad_response_unsafe
|
389
|
-
c =
|
414
|
+
c = basic_connection
|
390
415
|
def c.request(*a)
|
391
416
|
if instance_variable_defined? :@request then
|
392
417
|
raise 'POST must not be retried'
|
@@ -415,7 +440,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
415
440
|
|
416
441
|
req = c.req
|
417
442
|
|
418
|
-
|
443
|
+
assert_kind_of Net::HTTPResponse, res
|
419
444
|
refute_nil body
|
420
445
|
|
421
446
|
assert_kind_of Net::HTTP::Get, req
|
@@ -428,7 +453,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
428
453
|
end
|
429
454
|
|
430
455
|
def test_request_reset
|
431
|
-
c =
|
456
|
+
c = basic_connection
|
432
457
|
def c.request(*a) raise Errno::ECONNRESET end
|
433
458
|
|
434
459
|
e = assert_raises Net::HTTP::Persistent::Error do
|
@@ -440,23 +465,23 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
440
465
|
end
|
441
466
|
|
442
467
|
def test_request_reset_retry
|
443
|
-
c =
|
468
|
+
c = basic_connection
|
444
469
|
def c.request(*a)
|
445
|
-
|
446
|
-
|
470
|
+
if defined? @called then
|
471
|
+
Net::HTTPResponse.allocate
|
472
|
+
else
|
473
|
+
@called = true
|
474
|
+
raise Errno::ECONNRESET
|
447
475
|
end
|
448
|
-
|
449
|
-
raise Errno::ECONNRESET
|
450
476
|
end
|
451
477
|
|
452
|
-
|
478
|
+
@http.request @uri
|
453
479
|
|
454
|
-
assert_equal :response, res
|
455
480
|
assert c.finished?
|
456
481
|
end
|
457
482
|
|
458
483
|
def test_request_reset_unsafe
|
459
|
-
c =
|
484
|
+
c = basic_connection
|
460
485
|
def c.request(*a)
|
461
486
|
if instance_variable_defined? :@request then
|
462
487
|
raise 'POST must not be retried'
|
@@ -479,11 +504,9 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
479
504
|
|
480
505
|
post = Net::HTTP::Post.new @uri.path
|
481
506
|
|
482
|
-
|
507
|
+
@http.request @uri, post
|
483
508
|
req = c.req
|
484
509
|
|
485
|
-
assert_equal :response, res
|
486
|
-
|
487
510
|
assert_same post, req
|
488
511
|
end
|
489
512
|
|
@@ -505,6 +528,18 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
505
528
|
refute_same rs, reqs
|
506
529
|
end
|
507
530
|
|
531
|
+
def test_shutdown_not_started
|
532
|
+
c = Object.new
|
533
|
+
def c.finish() raise IOError end
|
534
|
+
|
535
|
+
conns["#{@uri.host}:#{@uri.port}"] = c
|
536
|
+
|
537
|
+
@http.shutdown
|
538
|
+
|
539
|
+
assert_nil Thread.current[@http.connection_key]
|
540
|
+
assert_nil Thread.current[@http.request_key]
|
541
|
+
end
|
542
|
+
|
508
543
|
def test_shutdown_no_connections
|
509
544
|
@http.shutdown
|
510
545
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http-persistent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 1.2.5
|
8
|
+
- 3
|
9
|
+
version: "1.3"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Eric Hodel
|
@@ -36,7 +35,7 @@ cert_chain:
|
|
36
35
|
x52qPcexcYZR7w==
|
37
36
|
-----END CERTIFICATE-----
|
38
37
|
|
39
|
-
date: 2010-
|
38
|
+
date: 2010-09-08 00:00:00 -07:00
|
40
39
|
default_executable:
|
41
40
|
dependencies:
|
42
41
|
- !ruby/object:Gem::Dependency
|
@@ -47,34 +46,18 @@ dependencies:
|
|
47
46
|
requirements:
|
48
47
|
- - ">="
|
49
48
|
- !ruby/object:Gem::Version
|
50
|
-
hash:
|
49
|
+
hash: 7
|
51
50
|
segments:
|
52
51
|
- 2
|
53
52
|
- 0
|
54
|
-
-
|
55
|
-
version: 2.0.
|
53
|
+
- 4
|
54
|
+
version: 2.0.4
|
56
55
|
type: :development
|
57
56
|
version_requirements: *id001
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: gemcutter
|
60
|
-
prerelease: false
|
61
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
|
-
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
hash: 11
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
- 5
|
70
|
-
- 0
|
71
|
-
version: 0.5.0
|
72
|
-
type: :development
|
73
|
-
version_requirements: *id002
|
74
57
|
- !ruby/object:Gem::Dependency
|
75
58
|
name: minitest
|
76
59
|
prerelease: false
|
77
|
-
requirement: &
|
60
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
78
61
|
none: false
|
79
62
|
requirements:
|
80
63
|
- - ">="
|
@@ -86,23 +69,23 @@ dependencies:
|
|
86
69
|
- 0
|
87
70
|
version: 1.5.0
|
88
71
|
type: :development
|
89
|
-
version_requirements: *
|
72
|
+
version_requirements: *id002
|
90
73
|
- !ruby/object:Gem::Dependency
|
91
74
|
name: hoe
|
92
75
|
prerelease: false
|
93
|
-
requirement: &
|
76
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
94
77
|
none: false
|
95
78
|
requirements:
|
96
79
|
- - ">="
|
97
80
|
- !ruby/object:Gem::Version
|
98
|
-
hash:
|
81
|
+
hash: 21
|
99
82
|
segments:
|
100
83
|
- 2
|
101
|
-
-
|
102
|
-
-
|
103
|
-
version: 2.
|
84
|
+
- 6
|
85
|
+
- 1
|
86
|
+
version: 2.6.1
|
104
87
|
type: :development
|
105
|
-
version_requirements: *
|
88
|
+
version_requirements: *id003
|
106
89
|
description: |-
|
107
90
|
Persistent connections using Net::HTTP plus a speed fix for 1.8. It's
|
108
91
|
thread-safe too!
|
metadata.gz.sig
CHANGED
Binary file
|