net-http-persistent 2.5.2 → 2.6
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 +5 -1
- data/History.txt +6 -0
- data/README.rdoc +6 -2
- data/Rakefile +1 -0
- data/lib/net/http/persistent.rb +33 -15
- data/test/test_net_http_persistent.rb +90 -6
- metadata +21 -21
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -45,8 +45,12 @@ connection is kept alive between requests:
|
|
45
45
|
# perform the POST, the URI is always required
|
46
46
|
response = http.request post_uri, post
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
# if you are done making http requests, or won't make requests for several
|
49
|
+
# minutes
|
50
|
+
http.shutdown
|
51
|
+
|
52
|
+
Please see the documentation on Net::HTTP::Persistent for more information,
|
53
|
+
including SSL connection verification, header handling and tunable options.
|
50
54
|
|
51
55
|
== INSTALL:
|
52
56
|
|
data/Rakefile
CHANGED
data/lib/net/http/persistent.rb
CHANGED
@@ -92,9 +92,9 @@ end
|
|
92
92
|
#
|
93
93
|
# === Idle Timeout
|
94
94
|
#
|
95
|
-
# If a connection hasn't been used for
|
95
|
+
# If a connection hasn't been used for this number of seconds it will automatically be
|
96
96
|
# reset upon the next use to avoid attempting to send to a closed connection.
|
97
|
-
#
|
97
|
+
# The default value is 5 seconds. nil means no timeout. Set through #idle_timeout.
|
98
98
|
#
|
99
99
|
# Reducing this value may help avoid the "too many connection resets" error
|
100
100
|
# when sending non-idempotent requests while increasing this value will cause
|
@@ -110,14 +110,6 @@ end
|
|
110
110
|
# The amount of time to wait for a connection to be opened. Set through
|
111
111
|
# #open_timeout.
|
112
112
|
#
|
113
|
-
# === Idle Timeout
|
114
|
-
#
|
115
|
-
# If a connection has not been used in this many seconds it will be reset when
|
116
|
-
# a request would use the connection. The default idle timeout is unlimited.
|
117
|
-
# If you know the server's idle timeout setting this value will eliminate
|
118
|
-
# failures from attempting non-idempotent requests on closed connections. Set
|
119
|
-
# through #idle_timeout.
|
120
|
-
#
|
121
113
|
# === Socket Options
|
122
114
|
#
|
123
115
|
# Socket options may be set on newly-created connections. See #socket_options
|
@@ -161,6 +153,18 @@ end
|
|
161
153
|
# The method of determining if the resource was created or not is unique to
|
162
154
|
# the particular service you are using. Of course, you will want to add
|
163
155
|
# protection from infinite looping.
|
156
|
+
#
|
157
|
+
# === Connection Termination
|
158
|
+
#
|
159
|
+
# If you are done using the Net::HTTP::Persistent instance you may shut down
|
160
|
+
# all the connections in the current thread with #shutdown. This is not
|
161
|
+
# recommended for normal use, it should only be used when it will be several
|
162
|
+
# minutes before you make another HTTP request.
|
163
|
+
#
|
164
|
+
# If you are using multiple threads, call #shutdown in each thread when the
|
165
|
+
# thread is done making requests. If you don't call shutdown, that's OK.
|
166
|
+
# Ruby will automatically garbage collect and shutdown your HTTP connections
|
167
|
+
# when the thread terminates.
|
164
168
|
|
165
169
|
class Net::HTTP::Persistent
|
166
170
|
|
@@ -172,7 +176,7 @@ class Net::HTTP::Persistent
|
|
172
176
|
##
|
173
177
|
# The version of Net::HTTP::Persistent you are using
|
174
178
|
|
175
|
-
VERSION = '2.
|
179
|
+
VERSION = '2.6'
|
176
180
|
|
177
181
|
##
|
178
182
|
# Error class for errors raised by Net::HTTP::Persistent. Various
|
@@ -496,8 +500,7 @@ class Net::HTTP::Persistent
|
|
496
500
|
connection = connections[connection_id]
|
497
501
|
ssl connection if use_ssl
|
498
502
|
else
|
499
|
-
|
500
|
-
reset connection unless last_used > max_age
|
503
|
+
reset connection if expired? connection
|
501
504
|
end
|
502
505
|
|
503
506
|
unless connection.started? then
|
@@ -544,6 +547,19 @@ class Net::HTTP::Persistent
|
|
544
547
|
CGI.escape str if str
|
545
548
|
end
|
546
549
|
|
550
|
+
##
|
551
|
+
# Returns true if the connection should be reset due to an idle timeout,
|
552
|
+
# false otherwise.
|
553
|
+
|
554
|
+
def expired? connection
|
555
|
+
return false unless @idle_timeout
|
556
|
+
return true if @idle_timeout.zero?
|
557
|
+
|
558
|
+
last_used = Thread.current[@timeout_key][connection.object_id]
|
559
|
+
|
560
|
+
Time.now - last_used > @idle_timeout
|
561
|
+
end
|
562
|
+
|
547
563
|
##
|
548
564
|
# Finishes the Net::HTTP +connection+
|
549
565
|
|
@@ -623,9 +639,11 @@ class Net::HTTP::Persistent
|
|
623
639
|
end
|
624
640
|
|
625
641
|
##
|
626
|
-
#
|
642
|
+
# Deprecated in favor of #expired?
|
643
|
+
|
644
|
+
def max_age # :nodoc:
|
645
|
+
return Time.now + 1 unless @idle_timeout
|
627
646
|
|
628
|
-
def max_age
|
629
647
|
Time.now - @idle_timeout
|
630
648
|
end
|
631
649
|
|
@@ -121,7 +121,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def reqs
|
124
|
-
Thread.current[@http.request_key] ||=
|
124
|
+
Thread.current[@http.request_key] ||= Hash.new 0
|
125
125
|
end
|
126
126
|
|
127
127
|
def ssl_conns
|
@@ -251,6 +251,60 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
251
251
|
assert_same c, conns[0]['example.com:80']
|
252
252
|
end
|
253
253
|
|
254
|
+
def test_connection_for_cached_expire_always
|
255
|
+
cached = basic_connection
|
256
|
+
cached.start
|
257
|
+
conns[0]['example.com:80'] = cached
|
258
|
+
reqs[cached.object_id] = 10
|
259
|
+
touts[cached.object_id] = Time.now # last used right now
|
260
|
+
|
261
|
+
@http.idle_timeout = 0
|
262
|
+
|
263
|
+
c = @http.connection_for @uri
|
264
|
+
|
265
|
+
assert c.started?
|
266
|
+
|
267
|
+
assert_same cached, c
|
268
|
+
|
269
|
+
assert_equal 0, reqs[cached.object_id],
|
270
|
+
'connection reset due to timeout'
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_connection_for_cached_expire_never
|
274
|
+
cached = basic_connection
|
275
|
+
cached.start
|
276
|
+
conns[0]['example.com:80'] = cached
|
277
|
+
reqs[cached.object_id] = 10
|
278
|
+
touts[cached.object_id] = Time.now # last used right now
|
279
|
+
|
280
|
+
@http.idle_timeout = nil
|
281
|
+
|
282
|
+
c = @http.connection_for @uri
|
283
|
+
|
284
|
+
assert c.started?
|
285
|
+
|
286
|
+
assert_same cached, c
|
287
|
+
|
288
|
+
assert_equal 10, reqs[cached.object_id],
|
289
|
+
'connection reset despite no timeout'
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_connection_for_cached_expired
|
293
|
+
cached = basic_connection
|
294
|
+
cached.start
|
295
|
+
conns[0]['example.com:80'] = cached
|
296
|
+
reqs[cached.object_id] = 10
|
297
|
+
touts[cached.object_id] = Time.now - 3600
|
298
|
+
|
299
|
+
c = @http.connection_for @uri
|
300
|
+
|
301
|
+
assert c.started?
|
302
|
+
|
303
|
+
assert_same cached, c
|
304
|
+
assert_equal 0, reqs[cached.object_id],
|
305
|
+
'connection not reset due to timeout'
|
306
|
+
end
|
307
|
+
|
254
308
|
def test_connection_for_finished_ssl
|
255
309
|
uri = URI.parse 'https://example.com/path'
|
256
310
|
c = @http.connection_for uri
|
@@ -412,7 +466,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
412
466
|
c = @http.connection_for @uri
|
413
467
|
|
414
468
|
assert c.started?
|
415
|
-
|
469
|
+
assert_equal 0, reqs[c.object_id]
|
416
470
|
|
417
471
|
assert_same cached, c
|
418
472
|
end
|
@@ -433,6 +487,26 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
433
487
|
assert_equal '+%3F', @http.escape(' ?')
|
434
488
|
end
|
435
489
|
|
490
|
+
def test_expired_eh
|
491
|
+
c = basic_connection
|
492
|
+
touts[c.object_id] = Time.now - 11
|
493
|
+
|
494
|
+
@http.idle_timeout = 0
|
495
|
+
assert @http.expired? c
|
496
|
+
|
497
|
+
@http.idle_timeout = 10
|
498
|
+
assert @http.expired? c
|
499
|
+
|
500
|
+
@http.idle_timeout = 11
|
501
|
+
assert @http.expired? c
|
502
|
+
|
503
|
+
@http.idle_timeout = 12
|
504
|
+
refute @http.expired? c
|
505
|
+
|
506
|
+
@http.idle_timeout = nil
|
507
|
+
refute @http.expired? c
|
508
|
+
end
|
509
|
+
|
436
510
|
def test_finish
|
437
511
|
c = basic_connection
|
438
512
|
reqs[c.object_id] = 5
|
@@ -441,7 +515,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
441
515
|
|
442
516
|
refute c.started?
|
443
517
|
assert c.finished?
|
444
|
-
|
518
|
+
assert_equal 0, reqs[c.object_id]
|
445
519
|
end
|
446
520
|
|
447
521
|
def test_finish_io_error
|
@@ -478,6 +552,10 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
478
552
|
|
479
553
|
def test_max_age
|
480
554
|
assert_in_delta Time.now - 5, @http.max_age
|
555
|
+
|
556
|
+
@http.idle_timeout = nil
|
557
|
+
|
558
|
+
assert_in_delta Time.now + 1, @http.max_age
|
481
559
|
end
|
482
560
|
|
483
561
|
def test_normalize_uri
|
@@ -693,6 +771,10 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
693
771
|
def test_request_close_1_0
|
694
772
|
c = connection
|
695
773
|
|
774
|
+
class << c
|
775
|
+
remove_method :request
|
776
|
+
end
|
777
|
+
|
696
778
|
def c.request req
|
697
779
|
@req = req
|
698
780
|
r = Net::HTTPResponse.allocate
|
@@ -740,6 +822,10 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
740
822
|
def test_request_connection_close_response
|
741
823
|
c = connection
|
742
824
|
|
825
|
+
class << c
|
826
|
+
remove_method :request
|
827
|
+
end
|
828
|
+
|
743
829
|
def c.request req
|
744
830
|
@req = req
|
745
831
|
r = Net::HTTPResponse.allocate
|
@@ -887,7 +973,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
887
973
|
assert c.started?
|
888
974
|
assert c.finished?
|
889
975
|
assert c.reset?
|
890
|
-
|
976
|
+
assert_equal 0, reqs[c.object_id]
|
891
977
|
assert_equal Net::HTTP::Persistent::EPOCH, touts[c.object_id]
|
892
978
|
end
|
893
979
|
|
@@ -948,7 +1034,6 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
948
1034
|
def test_shutdown
|
949
1035
|
ssl_conns
|
950
1036
|
c = connection
|
951
|
-
cs = conns
|
952
1037
|
rs = reqs
|
953
1038
|
ts = touts
|
954
1039
|
|
@@ -1177,7 +1262,6 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
|
|
1177
1262
|
|
1178
1263
|
def test_ssl_cleanup
|
1179
1264
|
uri1 = URI.parse 'https://one.example'
|
1180
|
-
uri2 = URI.parse 'https://two.example'
|
1181
1265
|
|
1182
1266
|
c1 = @http.connection_for uri1
|
1183
1267
|
|
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 2.5.2
|
8
|
+
- 6
|
9
|
+
version: "2.6"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Eric Hodel
|
@@ -16,9 +15,9 @@ bindir: bin
|
|
16
15
|
cert_chain:
|
17
16
|
- |
|
18
17
|
-----BEGIN CERTIFICATE-----
|
19
|
-
|
18
|
+
MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
|
20
19
|
YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
|
21
|
-
|
20
|
+
ZXQwHhcNMTIwMjI4MTc1NDI1WhcNMTMwMjI3MTc1NDI1WjBBMRAwDgYDVQQDDAdk
|
22
21
|
cmJyYWluMRgwFgYKCZImiZPyLGQBGRYI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dH9DNpd1
|
36
|
+
U81zGHMUBOvz/VGT6wJwYJ3emS2nfA2NOHFfgA==
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2012-
|
39
|
+
date: 2012-03-26 00:00:00 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
@@ -46,11 +46,11 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ~>
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
hash:
|
49
|
+
hash: 21
|
50
50
|
segments:
|
51
51
|
- 2
|
52
|
-
-
|
53
|
-
version: "2.
|
52
|
+
- 11
|
53
|
+
version: "2.11"
|
54
54
|
type: :development
|
55
55
|
version_requirements: *id001
|
56
56
|
- !ruby/object:Gem::Dependency
|
@@ -76,11 +76,11 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - ~>
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
hash:
|
79
|
+
hash: 35
|
80
80
|
segments:
|
81
81
|
- 2
|
82
|
-
-
|
83
|
-
version: "2.
|
82
|
+
- 16
|
83
|
+
version: "2.16"
|
84
84
|
type: :development
|
85
85
|
version_requirements: *id003
|
86
86
|
description: |-
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
requirements: []
|
147
147
|
|
148
148
|
rubyforge_project: net-http-persistent
|
149
|
-
rubygems_version: 1.8.
|
149
|
+
rubygems_version: 1.8.21
|
150
150
|
signing_key:
|
151
151
|
specification_version: 3
|
152
152
|
summary: Manages persistent connections using Net::HTTP plus a speed fix for Ruby 1.8
|
metadata.gz.sig
CHANGED
Binary file
|