net-http-persistent 4.0.2 → 4.0.8
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 +24 -0
- data/README.rdoc +1 -1
- data/lib/net/http/persistent/pool.rb +1 -1
- data/lib/net/http/persistent/timed_stack_multi.rb +12 -2
- data/lib/net/http/persistent.rb +122 -36
- data/test/test_net_http_persistent.rb +96 -3
- data/test/test_net_http_persistent_timed_stack_multi.rb +26 -7
- metadata +13 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e1c40dff68b8e70cac3630ca6b19ff70679fe7462974c835bb8638ab2b5dd5b
|
|
4
|
+
data.tar.gz: 95185bc4624e14eaae5b31e65a7b8e474a07f621020a5096966ccfec200bf6f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32089ec62a29518f3d6b1e9f1a1a677b65b1cc3b937506a9e3f985455f8c924b0c37c80516e9adc23420f8d25932607c4975cc042ec217bbd5bed2c626c2a57b
|
|
7
|
+
data.tar.gz: 28fc74bc92b2f63f752dfc8a2e86971f76b3cb064fe3647949005f9f1d7fa41d48d26122dd6f4c9d137d5255cd1b3dedc09ed779c937d12597fb9baba6c325e7
|
data/History.txt
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
=== 4.0.6 / 2024-12-04
|
|
2
|
+
|
|
3
|
+
Bug fixes:
|
|
4
|
+
|
|
5
|
+
* Allow ConnectionPool exceptions from checkout to bubble up to caller.
|
|
6
|
+
|
|
7
|
+
=== 4.0.5 / 2024-12-04
|
|
8
|
+
|
|
9
|
+
Bug fixes:
|
|
10
|
+
|
|
11
|
+
* Allow setting extra_chain_cert=
|
|
12
|
+
|
|
13
|
+
=== 4.0.4 / 2024-09-09
|
|
14
|
+
|
|
15
|
+
Bug fixes:
|
|
16
|
+
|
|
17
|
+
* Allow setting verify_hostname to false
|
|
18
|
+
|
|
19
|
+
=== 4.0.3 / 2024-09-09
|
|
20
|
+
|
|
21
|
+
Bug fixes:
|
|
22
|
+
|
|
23
|
+
* Handle Net::HTTP#verify_hostname was added in Ruby 3.0 or later. #120
|
|
24
|
+
|
|
1
25
|
=== 4.0.2 / 2023-03-29
|
|
2
26
|
|
|
3
27
|
Bug fixes:
|
data/README.rdoc
CHANGED
|
@@ -4,7 +4,7 @@ class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
|
|
|
4
4
|
attr_reader :key # :nodoc:
|
|
5
5
|
|
|
6
6
|
def initialize(options = {}, &block)
|
|
7
|
-
super
|
|
7
|
+
super(**options, &block)
|
|
8
8
|
|
|
9
9
|
@available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
|
|
10
10
|
@key = "current-#{@available.object_id}"
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:
|
|
2
2
|
|
|
3
|
+
##
|
|
4
|
+
# Detects if ConnectionPool 3.0+ is being used (needed for TimedStack subclass compatibility)
|
|
5
|
+
|
|
6
|
+
CP_USES_KEYWORD_ARGS = Gem::Version.new(ConnectionPool::VERSION) >= Gem::Version.new('3.0.0') # :nodoc:
|
|
7
|
+
|
|
3
8
|
##
|
|
4
9
|
# Returns a new hash that has arrays for keys
|
|
5
10
|
#
|
|
@@ -11,7 +16,11 @@ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nod
|
|
|
11
16
|
end
|
|
12
17
|
|
|
13
18
|
def initialize(size = 0, &block)
|
|
14
|
-
|
|
19
|
+
if CP_USES_KEYWORD_ARGS
|
|
20
|
+
super(size: size, &block)
|
|
21
|
+
else
|
|
22
|
+
super(size, &block)
|
|
23
|
+
end
|
|
15
24
|
|
|
16
25
|
@enqueued = 0
|
|
17
26
|
@ques = self.class.hash_of_arrays
|
|
@@ -63,7 +72,8 @@ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nod
|
|
|
63
72
|
if @created >= @max && @enqueued >= 1
|
|
64
73
|
oldest, = @lru.first
|
|
65
74
|
@lru.delete oldest
|
|
66
|
-
@ques[oldest].pop
|
|
75
|
+
connection = @ques[oldest].pop
|
|
76
|
+
connection.close if connection.respond_to?(:close)
|
|
67
77
|
|
|
68
78
|
@created -= 1
|
|
69
79
|
end
|
data/lib/net/http/persistent.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'net/http'
|
|
2
2
|
require 'uri'
|
|
3
|
-
require 'cgi'
|
|
3
|
+
require 'cgi/escape'
|
|
4
|
+
require 'cgi/util' unless defined?(CGI::EscapeExt)
|
|
4
5
|
require 'connection_pool'
|
|
5
6
|
|
|
6
7
|
begin
|
|
@@ -47,9 +48,8 @@ autoload :OpenSSL, 'openssl'
|
|
|
47
48
|
# # perform the POST, the URI is always required
|
|
48
49
|
# response http.request post_uri, post
|
|
49
50
|
#
|
|
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.
|
|
51
|
+
# ⚠ Note that for GET, HEAD and other requests that do not have a body,
|
|
52
|
+
# it uses URI#request_uri as default to send query params
|
|
53
53
|
#
|
|
54
54
|
# == TLS/SSL
|
|
55
55
|
#
|
|
@@ -65,6 +65,7 @@ autoload :OpenSSL, 'openssl'
|
|
|
65
65
|
# #ca_path :: Directory with certificate-authorities
|
|
66
66
|
# #cert_store :: An SSL certificate store
|
|
67
67
|
# #ciphers :: List of SSl ciphers allowed
|
|
68
|
+
# #extra_chain_cert :: Extra certificates to be added to the certificate chain
|
|
68
69
|
# #private_key :: The client's SSL private key
|
|
69
70
|
# #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new
|
|
70
71
|
# connection
|
|
@@ -73,6 +74,8 @@ autoload :OpenSSL, 'openssl'
|
|
|
73
74
|
# #verify_callback :: For server certificate verification
|
|
74
75
|
# #verify_depth :: Depth of certificate verification
|
|
75
76
|
# #verify_mode :: How connections should be verified
|
|
77
|
+
# #verify_hostname :: Use hostname verification for server certificate
|
|
78
|
+
# during the handshake
|
|
76
79
|
#
|
|
77
80
|
# == Proxies
|
|
78
81
|
#
|
|
@@ -179,7 +182,7 @@ class Net::HTTP::Persistent
|
|
|
179
182
|
##
|
|
180
183
|
# The version of Net::HTTP::Persistent you are using
|
|
181
184
|
|
|
182
|
-
VERSION = '4.0.
|
|
185
|
+
VERSION = '4.0.8'
|
|
183
186
|
|
|
184
187
|
##
|
|
185
188
|
# Error class for errors raised by Net::HTTP::Persistent. Various
|
|
@@ -270,6 +273,11 @@ class Net::HTTP::Persistent
|
|
|
270
273
|
|
|
271
274
|
attr_reader :ciphers
|
|
272
275
|
|
|
276
|
+
##
|
|
277
|
+
# Extra certificates to be added to the certificate chain
|
|
278
|
+
|
|
279
|
+
attr_reader :extra_chain_cert
|
|
280
|
+
|
|
273
281
|
##
|
|
274
282
|
# Sends debug_output to this IO via Net::HTTP#set_debug_output.
|
|
275
283
|
#
|
|
@@ -454,6 +462,28 @@ class Net::HTTP::Persistent
|
|
|
454
462
|
|
|
455
463
|
attr_reader :verify_mode
|
|
456
464
|
|
|
465
|
+
##
|
|
466
|
+
# HTTPS verify_hostname.
|
|
467
|
+
#
|
|
468
|
+
# If a client sets this to true and enables SNI with SSLSocket#hostname=,
|
|
469
|
+
# the hostname verification on the server certificate is performed
|
|
470
|
+
# automatically during the handshake using
|
|
471
|
+
# OpenSSL::SSL.verify_certificate_identity().
|
|
472
|
+
#
|
|
473
|
+
# You can set +verify_hostname+ as true to use hostname verification
|
|
474
|
+
# during the handshake.
|
|
475
|
+
#
|
|
476
|
+
# NOTE: This works with Ruby > 3.0.
|
|
477
|
+
|
|
478
|
+
attr_reader :verify_hostname
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
##
|
|
482
|
+
# Sets whether to ignore end-of-file when reading a response body
|
|
483
|
+
# with Content-Length headers.
|
|
484
|
+
|
|
485
|
+
attr_accessor :ignore_eof
|
|
486
|
+
|
|
457
487
|
##
|
|
458
488
|
# Creates a new Net::HTTP::Persistent.
|
|
459
489
|
#
|
|
@@ -493,6 +523,7 @@ class Net::HTTP::Persistent
|
|
|
493
523
|
@max_retries = 1
|
|
494
524
|
@socket_options = []
|
|
495
525
|
@ssl_generation = 0 # incremented when SSL session variables change
|
|
526
|
+
@ignore_eof = nil
|
|
496
527
|
|
|
497
528
|
@socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
|
|
498
529
|
Socket.const_defined? :TCP_NODELAY
|
|
@@ -513,6 +544,7 @@ class Net::HTTP::Persistent
|
|
|
513
544
|
@verify_callback = nil
|
|
514
545
|
@verify_depth = nil
|
|
515
546
|
@verify_mode = nil
|
|
547
|
+
@verify_hostname = nil
|
|
516
548
|
@cert_store = nil
|
|
517
549
|
|
|
518
550
|
@generation = 0 # incremented when proxy URI changes
|
|
@@ -574,6 +606,21 @@ class Net::HTTP::Persistent
|
|
|
574
606
|
reconnect_ssl
|
|
575
607
|
end
|
|
576
608
|
|
|
609
|
+
if Net::HTTP.method_defined?(:extra_chain_cert=)
|
|
610
|
+
##
|
|
611
|
+
# Extra certificates to be added to the certificate chain.
|
|
612
|
+
# It is only supported starting from Net::HTTP version 0.1.1
|
|
613
|
+
def extra_chain_cert= extra_chain_cert
|
|
614
|
+
@extra_chain_cert = extra_chain_cert
|
|
615
|
+
|
|
616
|
+
reconnect_ssl
|
|
617
|
+
end
|
|
618
|
+
else
|
|
619
|
+
def extra_chain_cert= _extra_chain_cert
|
|
620
|
+
raise "extra_chain_cert= is not supported by this version of Net::HTTP"
|
|
621
|
+
end
|
|
622
|
+
end
|
|
623
|
+
|
|
577
624
|
##
|
|
578
625
|
# Creates a new connection for +uri+
|
|
579
626
|
|
|
@@ -592,37 +639,50 @@ class Net::HTTP::Persistent
|
|
|
592
639
|
|
|
593
640
|
connection = @pool.checkout net_http_args
|
|
594
641
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
connection.ressl @ssl_generation if
|
|
598
|
-
connection.ssl_generation != @ssl_generation
|
|
642
|
+
begin
|
|
643
|
+
http = connection.http
|
|
599
644
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
start http
|
|
603
|
-
elsif expired? connection then
|
|
604
|
-
reset connection
|
|
605
|
-
end
|
|
645
|
+
connection.ressl @ssl_generation if
|
|
646
|
+
connection.ssl_generation != @ssl_generation
|
|
606
647
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
648
|
+
if not http.started? then
|
|
649
|
+
ssl http if use_ssl
|
|
650
|
+
start http
|
|
651
|
+
elsif expired? connection then
|
|
652
|
+
reset connection
|
|
653
|
+
end
|
|
612
654
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
655
|
+
http.ignore_eof = @ignore_eof if @ignore_eof
|
|
656
|
+
http.keep_alive_timeout = @idle_timeout if @idle_timeout
|
|
657
|
+
http.max_retries = @max_retries if http.respond_to?(:max_retries=)
|
|
658
|
+
http.read_timeout = @read_timeout if @read_timeout
|
|
659
|
+
http.write_timeout = @write_timeout if
|
|
660
|
+
@write_timeout && http.respond_to?(:write_timeout=)
|
|
661
|
+
|
|
662
|
+
return yield connection
|
|
663
|
+
rescue Errno::ECONNREFUSED
|
|
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
|
|
617
671
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
672
|
+
raise Error, "connection refused: #{address}:#{port}"
|
|
673
|
+
rescue Errno::EHOSTDOWN
|
|
674
|
+
if http.proxy?
|
|
675
|
+
address = http.proxy_address
|
|
676
|
+
port = http.proxy_port
|
|
677
|
+
else
|
|
678
|
+
address = http.address
|
|
679
|
+
port = http.port
|
|
680
|
+
end
|
|
622
681
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
682
|
+
raise Error, "host down: #{address}:#{port}"
|
|
683
|
+
ensure
|
|
684
|
+
@pool.checkin net_http_args
|
|
685
|
+
end
|
|
626
686
|
end
|
|
627
687
|
|
|
628
688
|
##
|
|
@@ -776,7 +836,7 @@ class Net::HTTP::Persistent
|
|
|
776
836
|
@proxy_connection_id = [nil, *@proxy_args].join ':'
|
|
777
837
|
|
|
778
838
|
if @proxy_uri.query then
|
|
779
|
-
@no_proxy =
|
|
839
|
+
@no_proxy = URI.decode_www_form(@proxy_uri.query).filter_map { |k, v| v if k == 'no_proxy' }.join(',').downcase.split(',').map { |x| x.strip }.reject { |x| x.empty? }
|
|
780
840
|
end
|
|
781
841
|
end
|
|
782
842
|
|
|
@@ -947,7 +1007,8 @@ class Net::HTTP::Persistent
|
|
|
947
1007
|
end
|
|
948
1008
|
|
|
949
1009
|
##
|
|
950
|
-
# Shuts down all connections
|
|
1010
|
+
# Shuts down all connections. Attempting to checkout a connection after
|
|
1011
|
+
# shutdown will raise an error.
|
|
951
1012
|
#
|
|
952
1013
|
# *NOTE*: Calling shutdown for can be dangerous!
|
|
953
1014
|
#
|
|
@@ -958,6 +1019,17 @@ class Net::HTTP::Persistent
|
|
|
958
1019
|
@pool.shutdown { |http| http.finish }
|
|
959
1020
|
end
|
|
960
1021
|
|
|
1022
|
+
##
|
|
1023
|
+
# Discard all existing connections. Subsequent checkouts will create
|
|
1024
|
+
# new connections as needed.
|
|
1025
|
+
#
|
|
1026
|
+
# If any thread is still using a connection it may cause an error! Call
|
|
1027
|
+
# #reload when you are completely done making requests!
|
|
1028
|
+
|
|
1029
|
+
def reload
|
|
1030
|
+
@pool.reload { |http| http.finish }
|
|
1031
|
+
end
|
|
1032
|
+
|
|
961
1033
|
##
|
|
962
1034
|
# Enables SSL on +connection+
|
|
963
1035
|
|
|
@@ -970,8 +1042,10 @@ class Net::HTTP::Persistent
|
|
|
970
1042
|
connection.min_version = @min_version if @min_version
|
|
971
1043
|
connection.max_version = @max_version if @max_version
|
|
972
1044
|
|
|
973
|
-
connection.verify_depth
|
|
974
|
-
connection.verify_mode
|
|
1045
|
+
connection.verify_depth = @verify_depth
|
|
1046
|
+
connection.verify_mode = @verify_mode
|
|
1047
|
+
connection.verify_hostname = @verify_hostname if
|
|
1048
|
+
@verify_hostname != nil && connection.respond_to?(:verify_hostname=)
|
|
975
1049
|
|
|
976
1050
|
if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
|
|
977
1051
|
not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
|
|
@@ -1013,6 +1087,10 @@ application:
|
|
|
1013
1087
|
connection.key = @private_key
|
|
1014
1088
|
end
|
|
1015
1089
|
|
|
1090
|
+
if defined?(@extra_chain_cert) and @extra_chain_cert
|
|
1091
|
+
connection.extra_chain_cert = @extra_chain_cert
|
|
1092
|
+
end
|
|
1093
|
+
|
|
1016
1094
|
connection.cert_store = if @cert_store then
|
|
1017
1095
|
@cert_store
|
|
1018
1096
|
else
|
|
@@ -1080,6 +1158,15 @@ application:
|
|
|
1080
1158
|
reconnect_ssl
|
|
1081
1159
|
end
|
|
1082
1160
|
|
|
1161
|
+
##
|
|
1162
|
+
# Sets the HTTPS verify_hostname.
|
|
1163
|
+
|
|
1164
|
+
def verify_hostname= verify_hostname
|
|
1165
|
+
@verify_hostname = verify_hostname
|
|
1166
|
+
|
|
1167
|
+
reconnect_ssl
|
|
1168
|
+
end
|
|
1169
|
+
|
|
1083
1170
|
##
|
|
1084
1171
|
# SSL verification callback.
|
|
1085
1172
|
|
|
@@ -1092,4 +1179,3 @@ end
|
|
|
1092
1179
|
|
|
1093
1180
|
require_relative 'persistent/connection'
|
|
1094
1181
|
require_relative 'persistent/pool'
|
|
1095
|
-
|
|
@@ -80,7 +80,7 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
80
80
|
:read_timeout, :open_timeout, :keep_alive_timeout
|
|
81
81
|
attr_accessor :ciphers, :ssl_timeout, :ssl_version, :min_version,
|
|
82
82
|
:max_version, :verify_depth, :verify_mode, :cert_store,
|
|
83
|
-
:ca_file, :ca_path, :cert, :key
|
|
83
|
+
:ca_file, :ca_path, :cert, :key, :ignore_eof
|
|
84
84
|
attr_reader :req, :debug_output
|
|
85
85
|
def initialize
|
|
86
86
|
@started, @finished = 0, 0
|
|
@@ -116,6 +116,9 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
116
116
|
end
|
|
117
117
|
def proxy_port
|
|
118
118
|
end
|
|
119
|
+
def proxy?
|
|
120
|
+
false
|
|
121
|
+
end
|
|
119
122
|
end
|
|
120
123
|
|
|
121
124
|
def basic_connection
|
|
@@ -244,6 +247,14 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
244
247
|
assert_equal 1, @http.ssl_generation
|
|
245
248
|
end
|
|
246
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
|
+
|
|
247
258
|
def test_connection_for
|
|
248
259
|
@http.open_timeout = 123
|
|
249
260
|
@http.read_timeout = 321
|
|
@@ -269,6 +280,16 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
269
280
|
assert_same used, stored
|
|
270
281
|
end
|
|
271
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
|
+
|
|
272
293
|
def test_connection_for_cached
|
|
273
294
|
cached = basic_connection
|
|
274
295
|
cached.http.start
|
|
@@ -982,7 +1003,7 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
982
1003
|
|
|
983
1004
|
# There's some roounding issue on jruby preventing this from passing
|
|
984
1005
|
unless RUBY_PLATFORM == "java"
|
|
985
|
-
assert_in_delta Time.now, c.last_use
|
|
1006
|
+
assert_in_delta Time.now, c.last_use, 0.003
|
|
986
1007
|
end
|
|
987
1008
|
|
|
988
1009
|
assert_equal 1, c.requests
|
|
@@ -1244,6 +1265,17 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
1244
1265
|
refute c2.http.finished?, 'present generation connection must not be finished'
|
|
1245
1266
|
end
|
|
1246
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
|
+
|
|
1247
1279
|
def test_ssl
|
|
1248
1280
|
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
|
1249
1281
|
|
|
@@ -1256,6 +1288,7 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
1256
1288
|
assert_equal OpenSSL::SSL::VERIFY_PEER, c.verify_mode
|
|
1257
1289
|
assert_kind_of OpenSSL::X509::Store, c.cert_store
|
|
1258
1290
|
assert_nil c.verify_callback
|
|
1291
|
+
assert_nil c.verify_hostname if c.respond_to?(:verify_hostname)
|
|
1259
1292
|
end
|
|
1260
1293
|
|
|
1261
1294
|
def test_ssl_ca_file
|
|
@@ -1339,6 +1372,49 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
1339
1372
|
assert_equal OpenSSL::SSL::VERIFY_NONE, c.verify_mode
|
|
1340
1373
|
end
|
|
1341
1374
|
|
|
1375
|
+
def test_ssl_enable_verify_hostname
|
|
1376
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
|
1377
|
+
|
|
1378
|
+
@http.verify_hostname = true
|
|
1379
|
+
c = Net::HTTP.new 'localhost', 80
|
|
1380
|
+
|
|
1381
|
+
skip 'net/http doesn\'t provide verify_hostname= method' unless
|
|
1382
|
+
c.respond_to?(:verify_hostname=)
|
|
1383
|
+
|
|
1384
|
+
@http.ssl c
|
|
1385
|
+
|
|
1386
|
+
assert c.use_ssl?
|
|
1387
|
+
assert c.verify_hostname
|
|
1388
|
+
end
|
|
1389
|
+
|
|
1390
|
+
def test_ssl_disable_verify_hostname
|
|
1391
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
|
1392
|
+
|
|
1393
|
+
@http.verify_hostname = false
|
|
1394
|
+
c = Net::HTTP.new 'localhost', 80
|
|
1395
|
+
|
|
1396
|
+
skip 'net/http doesn\'t provide verify_hostname= method' unless
|
|
1397
|
+
c.respond_to?(:verify_hostname=)
|
|
1398
|
+
|
|
1399
|
+
@http.ssl c
|
|
1400
|
+
|
|
1401
|
+
assert c.use_ssl?
|
|
1402
|
+
assert c.verify_hostname == false
|
|
1403
|
+
end
|
|
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
|
|
1417
|
+
|
|
1342
1418
|
def test_ssl_warning
|
|
1343
1419
|
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
|
1344
1420
|
|
|
@@ -1454,5 +1530,22 @@ class TestNetHttpPersistent < Minitest::Test
|
|
|
1454
1530
|
connection.close
|
|
1455
1531
|
end
|
|
1456
1532
|
end
|
|
1457
|
-
end
|
|
1458
1533
|
|
|
1534
|
+
def test_ignore_eof
|
|
1535
|
+
@http.ignore_eof = true
|
|
1536
|
+
|
|
1537
|
+
connection
|
|
1538
|
+
|
|
1539
|
+
@http.connection_for @uri do |c|
|
|
1540
|
+
assert c.http.ignore_eof
|
|
1541
|
+
end
|
|
1542
|
+
|
|
1543
|
+
@http.ignore_eof = false
|
|
1544
|
+
|
|
1545
|
+
connection
|
|
1546
|
+
|
|
1547
|
+
@http.connection_for @uri do |c|
|
|
1548
|
+
assert !c.http.ignore_eof
|
|
1549
|
+
end
|
|
1550
|
+
end
|
|
1551
|
+
end
|
|
@@ -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
|
|
|
@@ -24,7 +29,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
|
24
29
|
|
|
25
30
|
assert_empty stack
|
|
26
31
|
|
|
27
|
-
stack.push connection_args:
|
|
32
|
+
stack.push popped, connection_args: 'default'
|
|
28
33
|
|
|
29
34
|
refute_empty stack
|
|
30
35
|
end
|
|
@@ -38,7 +43,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
|
38
43
|
|
|
39
44
|
assert_equal 0, stack.length
|
|
40
45
|
|
|
41
|
-
stack.push connection_args:
|
|
46
|
+
stack.push popped, connection_args: 'default'
|
|
42
47
|
|
|
43
48
|
assert_equal 1, stack.length
|
|
44
49
|
end
|
|
@@ -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
|
|
@@ -96,7 +113,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
|
96
113
|
|
|
97
114
|
conn = stack.pop
|
|
98
115
|
|
|
99
|
-
stack.push connection_args:
|
|
116
|
+
stack.push conn, connection_args: 'default'
|
|
100
117
|
|
|
101
118
|
refute_empty stack
|
|
102
119
|
end
|
|
@@ -108,14 +125,16 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
|
108
125
|
called << object
|
|
109
126
|
end
|
|
110
127
|
|
|
111
|
-
|
|
128
|
+
obj = Object.new
|
|
129
|
+
@stack.push obj, connection_args: 'default'
|
|
112
130
|
|
|
113
131
|
refute_empty called
|
|
114
132
|
assert_empty @stack
|
|
115
133
|
end
|
|
116
134
|
|
|
117
135
|
def test_shutdown
|
|
118
|
-
|
|
136
|
+
obj = Object.new
|
|
137
|
+
@stack.push obj, connection_args: 'default'
|
|
119
138
|
|
|
120
139
|
called = []
|
|
121
140
|
|
metadata
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
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.8
|
|
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: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: connection_pool
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: 2.2.4
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '4'
|
|
20
22
|
type: :runtime
|
|
21
23
|
prerelease: false
|
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
25
|
requirements:
|
|
24
|
-
- - "
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: 2.2.4
|
|
29
|
+
- - "<"
|
|
25
30
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
31
|
+
version: '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:
|
|
84
|
-
signing_key:
|
|
87
|
+
rubygems_version: 4.0.3
|
|
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
|