net-http-persistent 4.0.4 → 4.0.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.
- checksums.yaml +4 -4
- data/History.txt +12 -0
- data/README.rdoc +1 -1
- data/lib/net/http/persistent/timed_stack_multi.rb +2 -1
- data/lib/net/http/persistent.rb +78 -40
- data/test/test_net_http_persistent.rb +41 -0
- data/test/test_net_http_persistent_timed_stack_multi.rb +19 -2
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85a943098d06763f4de093bc75563f2df1bb927471fadf3dd3b2c8bd9df22d36
|
4
|
+
data.tar.gz: 49b04bd17537e5d4939c987b64ac40e1747ee22fa9d5a98751962810bf279153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa114cb93989e4bd4d025b6c3823856efe39d0f06206d6f34605125d780306b7e22fc0c97e9a18737f9fe6d68acc73c23ab125a7f80ee68d90a93aa305dafbc
|
7
|
+
data.tar.gz: 492748215d7b48f67c6221728fb566297831cfc75715f97cc55dd8ac329b1082a1bac9163657961bb7fa8baef0ff407c74b1ff4a2c8f0286dcfe030109944549
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -63,7 +63,8 @@ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nod
|
|
63
63
|
if @created >= @max && @enqueued >= 1
|
64
64
|
oldest, = @lru.first
|
65
65
|
@lru.delete oldest
|
66
|
-
@ques[oldest].pop
|
66
|
+
connection = @ques[oldest].pop
|
67
|
+
connection.close if connection.respond_to?(:close)
|
67
68
|
|
68
69
|
@created -= 1
|
69
70
|
end
|
data/lib/net/http/persistent.rb
CHANGED
@@ -47,9 +47,8 @@ autoload :OpenSSL, 'openssl'
|
|
47
47
|
# # perform the POST, the URI is always required
|
48
48
|
# response http.request post_uri, post
|
49
49
|
#
|
50
|
-
# Note that for GET, HEAD and other requests that do not have a body
|
51
|
-
#
|
52
|
-
# params which are sent in the body for other requests.
|
50
|
+
# ⚠ Note that for GET, HEAD and other requests that do not have a body,
|
51
|
+
# it uses URI#request_uri as default to send query params
|
53
52
|
#
|
54
53
|
# == TLS/SSL
|
55
54
|
#
|
@@ -65,6 +64,7 @@ autoload :OpenSSL, 'openssl'
|
|
65
64
|
# #ca_path :: Directory with certificate-authorities
|
66
65
|
# #cert_store :: An SSL certificate store
|
67
66
|
# #ciphers :: List of SSl ciphers allowed
|
67
|
+
# #extra_chain_cert :: Extra certificates to be added to the certificate chain
|
68
68
|
# #private_key :: The client's SSL private key
|
69
69
|
# #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new
|
70
70
|
# connection
|
@@ -181,7 +181,7 @@ class Net::HTTP::Persistent
|
|
181
181
|
##
|
182
182
|
# The version of Net::HTTP::Persistent you are using
|
183
183
|
|
184
|
-
VERSION = '4.0.
|
184
|
+
VERSION = '4.0.6'
|
185
185
|
|
186
186
|
##
|
187
187
|
# Error class for errors raised by Net::HTTP::Persistent. Various
|
@@ -272,6 +272,11 @@ class Net::HTTP::Persistent
|
|
272
272
|
|
273
273
|
attr_reader :ciphers
|
274
274
|
|
275
|
+
##
|
276
|
+
# Extra certificates to be added to the certificate chain
|
277
|
+
|
278
|
+
attr_reader :extra_chain_cert
|
279
|
+
|
275
280
|
##
|
276
281
|
# Sends debug_output to this IO via Net::HTTP#set_debug_output.
|
277
282
|
#
|
@@ -592,6 +597,21 @@ class Net::HTTP::Persistent
|
|
592
597
|
reconnect_ssl
|
593
598
|
end
|
594
599
|
|
600
|
+
if Net::HTTP.method_defined?(:extra_chain_cert=)
|
601
|
+
##
|
602
|
+
# Extra certificates to be added to the certificate chain.
|
603
|
+
# It is only supported starting from Net::HTTP version 0.1.1
|
604
|
+
def extra_chain_cert= extra_chain_cert
|
605
|
+
@extra_chain_cert = extra_chain_cert
|
606
|
+
|
607
|
+
reconnect_ssl
|
608
|
+
end
|
609
|
+
else
|
610
|
+
def extra_chain_cert= _extra_chain_cert
|
611
|
+
raise "extra_chain_cert= is not supported by this version of Net::HTTP"
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
595
615
|
##
|
596
616
|
# Creates a new connection for +uri+
|
597
617
|
|
@@ -610,47 +630,49 @@ class Net::HTTP::Persistent
|
|
610
630
|
|
611
631
|
connection = @pool.checkout net_http_args
|
612
632
|
|
613
|
-
|
633
|
+
begin
|
634
|
+
http = connection.http
|
614
635
|
|
615
|
-
|
616
|
-
|
636
|
+
connection.ressl @ssl_generation if
|
637
|
+
connection.ssl_generation != @ssl_generation
|
617
638
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
639
|
+
if not http.started? then
|
640
|
+
ssl http if use_ssl
|
641
|
+
start http
|
642
|
+
elsif expired? connection then
|
643
|
+
reset connection
|
644
|
+
end
|
624
645
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
646
|
+
http.keep_alive_timeout = @idle_timeout if @idle_timeout
|
647
|
+
http.max_retries = @max_retries if http.respond_to?(:max_retries=)
|
648
|
+
http.read_timeout = @read_timeout if @read_timeout
|
649
|
+
http.write_timeout = @write_timeout if
|
650
|
+
@write_timeout && http.respond_to?(:write_timeout=)
|
651
|
+
|
652
|
+
return yield connection
|
653
|
+
rescue Errno::ECONNREFUSED
|
654
|
+
if http.proxy?
|
655
|
+
address = http.proxy_address
|
656
|
+
port = http.proxy_port
|
657
|
+
else
|
658
|
+
address = http.address
|
659
|
+
port = http.port
|
660
|
+
end
|
630
661
|
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
662
|
+
raise Error, "connection refused: #{address}:#{port}"
|
663
|
+
rescue Errno::EHOSTDOWN
|
664
|
+
if http.proxy?
|
665
|
+
address = http.proxy_address
|
666
|
+
port = http.proxy_port
|
667
|
+
else
|
668
|
+
address = http.address
|
669
|
+
port = http.port
|
670
|
+
end
|
640
671
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
address = http.proxy_address
|
645
|
-
port = http.proxy_port
|
646
|
-
else
|
647
|
-
address = http.address
|
648
|
-
port = http.port
|
672
|
+
raise Error, "host down: #{address}:#{port}"
|
673
|
+
ensure
|
674
|
+
@pool.checkin net_http_args
|
649
675
|
end
|
650
|
-
|
651
|
-
raise Error, "host down: #{address}:#{port}"
|
652
|
-
ensure
|
653
|
-
@pool.checkin net_http_args
|
654
676
|
end
|
655
677
|
|
656
678
|
##
|
@@ -975,7 +997,8 @@ class Net::HTTP::Persistent
|
|
975
997
|
end
|
976
998
|
|
977
999
|
##
|
978
|
-
# Shuts down all connections
|
1000
|
+
# Shuts down all connections. Attempting to checkout a connection after
|
1001
|
+
# shutdown will raise an error.
|
979
1002
|
#
|
980
1003
|
# *NOTE*: Calling shutdown for can be dangerous!
|
981
1004
|
#
|
@@ -986,6 +1009,17 @@ class Net::HTTP::Persistent
|
|
986
1009
|
@pool.shutdown { |http| http.finish }
|
987
1010
|
end
|
988
1011
|
|
1012
|
+
##
|
1013
|
+
# Discard all existing connections. Subsequent checkouts will create
|
1014
|
+
# new connections as needed.
|
1015
|
+
#
|
1016
|
+
# If any thread is still using a connection it may cause an error! Call
|
1017
|
+
# #reload when you are completely done making requests!
|
1018
|
+
|
1019
|
+
def reload
|
1020
|
+
@pool.reload { |http| http.finish }
|
1021
|
+
end
|
1022
|
+
|
989
1023
|
##
|
990
1024
|
# Enables SSL on +connection+
|
991
1025
|
|
@@ -1043,6 +1077,10 @@ application:
|
|
1043
1077
|
connection.key = @private_key
|
1044
1078
|
end
|
1045
1079
|
|
1080
|
+
if defined?(@extra_chain_cert) and @extra_chain_cert
|
1081
|
+
connection.extra_chain_cert = @extra_chain_cert
|
1082
|
+
end
|
1083
|
+
|
1046
1084
|
connection.cert_store = if @cert_store then
|
1047
1085
|
@cert_store
|
1048
1086
|
else
|
@@ -247,6 +247,14 @@ class TestNetHttpPersistent < Minitest::Test
|
|
247
247
|
assert_equal 1, @http.ssl_generation
|
248
248
|
end
|
249
249
|
|
250
|
+
def test_extra_chain_cert_equals
|
251
|
+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
|
252
|
+
@http.extra_chain_cert = :extra_chain_cert
|
253
|
+
|
254
|
+
assert_equal :extra_chain_cert, @http.extra_chain_cert
|
255
|
+
assert_equal 1, @http.ssl_generation
|
256
|
+
end
|
257
|
+
|
250
258
|
def test_connection_for
|
251
259
|
@http.open_timeout = 123
|
252
260
|
@http.read_timeout = 321
|
@@ -272,6 +280,16 @@ class TestNetHttpPersistent < Minitest::Test
|
|
272
280
|
assert_same used, stored
|
273
281
|
end
|
274
282
|
|
283
|
+
def test_connection_for_exhaustion
|
284
|
+
@http = Net::HTTP::Persistent.new pool_size: 0
|
285
|
+
|
286
|
+
assert_raises Timeout::Error do
|
287
|
+
@http.connection_for @uri do |c|
|
288
|
+
assert_same nil, c
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
275
293
|
def test_connection_for_cached
|
276
294
|
cached = basic_connection
|
277
295
|
cached.http.start
|
@@ -1247,6 +1265,17 @@ class TestNetHttpPersistent < Minitest::Test
|
|
1247
1265
|
refute c2.http.finished?, 'present generation connection must not be finished'
|
1248
1266
|
end
|
1249
1267
|
|
1268
|
+
def test_reload
|
1269
|
+
c = connection
|
1270
|
+
|
1271
|
+
@http.reload
|
1272
|
+
|
1273
|
+
c2 = connection
|
1274
|
+
|
1275
|
+
assert c.http.finished?, 'last-generation connection must be finished'
|
1276
|
+
refute c2.http.finished?, 'present generation connection must not be finished'
|
1277
|
+
end
|
1278
|
+
|
1250
1279
|
def test_ssl
|
1251
1280
|
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1252
1281
|
|
@@ -1373,6 +1402,18 @@ class TestNetHttpPersistent < Minitest::Test
|
|
1373
1402
|
assert c.verify_hostname == false
|
1374
1403
|
end
|
1375
1404
|
|
1405
|
+
def test_ssl_extra_chain_cert
|
1406
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1407
|
+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
|
1408
|
+
|
1409
|
+
@http.extra_chain_cert = :extra_chain_cert
|
1410
|
+
c = Net::HTTP.new 'localhost', 80
|
1411
|
+
|
1412
|
+
@http.ssl c
|
1413
|
+
|
1414
|
+
assert c.use_ssl?
|
1415
|
+
assert_equal :extra_chain_cert, c.extra_chain_cert
|
1416
|
+
end
|
1376
1417
|
|
1377
1418
|
def test_ssl_warning
|
1378
1419
|
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
@@ -4,10 +4,15 @@ require 'net/http/persistent'
|
|
4
4
|
class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
5
5
|
|
6
6
|
class Connection
|
7
|
-
attr_reader :host
|
7
|
+
attr_reader :host, :closed
|
8
8
|
|
9
9
|
def initialize(host)
|
10
10
|
@host = host
|
11
|
+
@closed = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def close
|
15
|
+
@closed = true
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
@@ -57,7 +62,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
57
62
|
@stack.pop timeout: 0
|
58
63
|
end
|
59
64
|
|
60
|
-
|
65
|
+
assert_includes e.message, 'Waited 0 sec'
|
61
66
|
end
|
62
67
|
|
63
68
|
def test_pop_full
|
@@ -69,6 +74,18 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
69
74
|
assert_empty stack
|
70
75
|
end
|
71
76
|
|
77
|
+
def test_pop_closes_extra_connections
|
78
|
+
stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { |host| Connection.new(host) }
|
79
|
+
|
80
|
+
a_conn = stack.pop connection_args: 'a.example'
|
81
|
+
stack.push a_conn, connection_args: 'a.example'
|
82
|
+
|
83
|
+
b_conn = stack.pop connection_args: 'b.example'
|
84
|
+
|
85
|
+
assert a_conn.closed
|
86
|
+
refute b_conn.closed
|
87
|
+
end
|
88
|
+
|
72
89
|
def test_pop_wait
|
73
90
|
thread = Thread.start do
|
74
91
|
@stack.pop
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http-persistent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-05-29 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: connection_pool
|
@@ -17,6 +16,9 @@ dependencies:
|
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '2.2'
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.2.4
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +26,9 @@ dependencies:
|
|
24
26
|
- - "~>"
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: '2.2'
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.2.4
|
27
32
|
description: |-
|
28
33
|
Manages persistent connections using Net::HTTP including a thread pool for
|
29
34
|
connecting to multiple hosts.
|
@@ -63,7 +68,6 @@ licenses:
|
|
63
68
|
- MIT
|
64
69
|
metadata:
|
65
70
|
homepage_uri: https://github.com/drbrain/net-http-persistent
|
66
|
-
post_install_message:
|
67
71
|
rdoc_options:
|
68
72
|
- "--main"
|
69
73
|
- README.rdoc
|
@@ -80,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
84
|
- !ruby/object:Gem::Version
|
81
85
|
version: '0'
|
82
86
|
requirements: []
|
83
|
-
rubygems_version: 3.0.
|
84
|
-
signing_key:
|
87
|
+
rubygems_version: 3.6.0.dev
|
85
88
|
specification_version: 4
|
86
89
|
summary: Manages persistent connections using Net::HTTP including a thread pool for
|
87
90
|
connecting to multiple hosts
|