net-http-persistent 4.0.1 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 776350367e44e2bf8c4e4fd84b1fd1c03eca4c785462c3dd58c8f214fc9b74ab
4
- data.tar.gz: f79c075c1a091389c030137bdcbcf5ef3079fbb66702a7ebf6ef8e8bfb75146d
3
+ metadata.gz: dda1829232ea53f61dd44b4added8e65777661bb9c2bb8f4c49014c7dbbe3d1d
4
+ data.tar.gz: 9321f0aad6dbc328d2612212321e9f2daa8cad2330f677208c55089676f666e7
5
5
  SHA512:
6
- metadata.gz: 10ec9cc95f92954730b37ea924ef4eea9491b7fa5f5b913e9dea762e19381a8f9516caa4201aafe33f8028984c0aed429f6d7533d2056375f49558882fcc67dc
7
- data.tar.gz: cd107612612cb1f70513bfe858dd75b6d8aeb2a5415b892e1fa98158b126152820c0b7c3b6a4ba2f0b6da42157da230182f49ffd0453c5b9779c6db29f088958
6
+ metadata.gz: 9ca608a9a2f899b0ac3636d848f4581085fae57eec74527ed457e21a6c1988d909123cd4d4e102ab77d53a3839e9778adc140ecdff9d57d5f1dcbcd2c2d69c5c
7
+ data.tar.gz: 03622a828eea0b5266511a39afc8bafdccf41d1e7e572cf04e0e23548104307d857b33bdaa387ed12ef46f8fd890762a8d39fa3ac9a4e2ca7d70026cd9bfd1b5
data/Gemfile CHANGED
@@ -1,15 +1,14 @@
1
1
  # -*- ruby -*-
2
2
 
3
- # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
-
5
3
  source "https://rubygems.org/"
6
4
 
7
- gem "connection_pool", "~>2.2"
5
+ gemspec
8
6
 
9
- gem "minitest", "~>5.11", :group => [:development, :test]
10
- gem "hoe-bundler", "~>1.5", :group => [:development, :test]
11
- gem "hoe-travis", "~>1.4", ">=1.4.1", :group => [:development, :test]
7
+ gem "rake", "~>13.0"
8
+ gem "minitest", "~>5.15", :group => [:development, :test]
12
9
  gem "rdoc", ">=4.0", "<7", :group => [:development, :test]
13
- gem "hoe", "~>3.17", :group => [:development, :test]
10
+ gem "rake-manifest", "~>0.2"
11
+
12
+ gem 'net-http-pipeline', '~> 1.0' if ENV['CI_MATRIX'] == 'pipeline'
14
13
 
15
14
  # vim: syntax=ruby
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ === 4.0.2 / 2024-09-09
2
+
3
+ Bug fixes:
4
+
5
+ * Handle Net::HTTP#verify_hostname was added in Ruby 3.0 or later. #120
6
+
7
+ === 4.0.2 / 2023-03-29
8
+
9
+ Bug fixes:
10
+
11
+ * Fix compatibility with `connection_pool 2.4+`
12
+
1
13
  === 4.0.1 / 2021-01-12
2
14
 
3
15
  Bug fixes:
data/Manifest.txt CHANGED
@@ -1,6 +1,5 @@
1
1
  .autotest
2
2
  .gemtest
3
- .travis.yml
4
3
  Gemfile
5
4
  History.txt
6
5
  Manifest.txt
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = net-http-persistent
2
2
 
3
3
  home :: https://github.com/drbrain/net-http-persistent
4
- rdoc :: http://docs.seattlerb.org/net-http-persistent
4
+ rdoc :: https://rdoc.info/gems/net-http-persistent
5
5
 
6
6
  == DESCRIPTION:
7
7
 
data/Rakefile CHANGED
@@ -1,31 +1,25 @@
1
1
  # -*- ruby -*-
2
2
 
3
- require 'hoe'
4
-
5
- Hoe.plugin :bundler
6
- Hoe.plugin :git
7
- Hoe.plugin :minitest
8
- Hoe.plugin :travis
9
-
10
- Hoe.spec 'net-http-persistent' do
11
- developer 'Eric Hodel', 'drbrain@segment7.net'
12
-
13
- self.readme_file = 'README.rdoc'
14
- self.extra_rdoc_files += Dir['*.rdoc']
15
-
16
- self.require_ruby_version '>= 2.3'
17
-
18
- license 'MIT'
19
-
20
- rdoc_locations <<
21
- 'docs-push.seattlerb.org:/data/www/docs.seattlerb.org/net-http-persistent/'
22
-
23
- dependency 'connection_pool', '~> 2.2'
24
- dependency 'minitest', '~> 5.2', :development
25
- dependency 'hoe-bundler', '~> 1.5', :development
26
- dependency 'hoe-travis', ['~> 1.4', '>= 1.4.1'], :development
27
- dependency 'net-http-pipeline', '~> 1.0' if
28
- ENV['TRAVIS_MATRIX'] == 'pipeline'
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new
8
+
9
+ require "rake/manifest"
10
+
11
+ Rake::Manifest::Task.new do |t|
12
+ t.patterns = [
13
+ ".autotest",
14
+ ".gemtest",
15
+ ".travis.yml",
16
+ "Gemfile",
17
+ "History.txt",
18
+ "Manifest.txt",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "{test,lib}/**/*"
22
+ ]
29
23
  end
30
24
 
31
25
  # vim: syntax=Ruby
@@ -25,6 +25,7 @@ class Net::HTTP::Persistent::Connection # :nodoc:
25
25
  ensure
26
26
  reset
27
27
  end
28
+ alias_method :close, :finish
28
29
 
29
30
  def reset
30
31
  @last_use = Net::HTTP::Persistent::EPOCH
@@ -11,20 +11,32 @@ class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
11
11
  end
12
12
 
13
13
  def checkin net_http_args
14
- stack = Thread.current[@key][net_http_args] ||= []
14
+ if net_http_args.is_a?(Hash) && net_http_args.size == 1 && net_http_args[:force]
15
+ # ConnectionPool 2.4+ calls `checkin(force: true)` after fork.
16
+ # When this happens, we should remove all connections from Thread.current
17
+ if stacks = Thread.current[@key]
18
+ stacks.each do |http_args, connections|
19
+ connections.each do |conn|
20
+ @available.push conn, connection_args: http_args
21
+ end
22
+ connections.clear
23
+ end
24
+ end
25
+ else
26
+ stack = Thread.current[@key][net_http_args] ||= []
15
27
 
16
- raise ConnectionPool::Error, 'no connections are checked out' if
17
- stack.empty?
28
+ raise ConnectionPool::Error, 'no connections are checked out' if
29
+ stack.empty?
18
30
 
19
- conn = stack.pop
31
+ conn = stack.pop
20
32
 
21
- if stack.empty?
22
- @available.push conn, connection_args: net_http_args
33
+ if stack.empty?
34
+ @available.push conn, connection_args: net_http_args
23
35
 
24
- Thread.current[@key].delete(net_http_args)
25
- Thread.current[@key] = nil if Thread.current[@key].empty?
36
+ Thread.current[@key].delete(net_http_args)
37
+ Thread.current[@key] = nil if Thread.current[@key].empty?
38
+ end
26
39
  end
27
-
28
40
  nil
29
41
  end
30
42
 
@@ -73,6 +73,8 @@ autoload :OpenSSL, 'openssl'
73
73
  # #verify_callback :: For server certificate verification
74
74
  # #verify_depth :: Depth of certificate verification
75
75
  # #verify_mode :: How connections should be verified
76
+ # #verify_hostname :: Use hostname verification for server certificate
77
+ # during the handshake
76
78
  #
77
79
  # == Proxies
78
80
  #
@@ -164,7 +166,14 @@ class Net::HTTP::Persistent
164
166
  # limits (typically windows).
165
167
 
166
168
  if Process.const_defined? :RLIMIT_NOFILE
167
- DEFAULT_POOL_SIZE = Process.getrlimit(Process::RLIMIT_NOFILE).first / 4
169
+ open_file_limits = Process.getrlimit(Process::RLIMIT_NOFILE)
170
+
171
+ # Under JRuby on Windows Process responds to `getrlimit` but returns something that does not match docs
172
+ if open_file_limits.respond_to?(:first)
173
+ DEFAULT_POOL_SIZE = open_file_limits.first / 4
174
+ else
175
+ DEFAULT_POOL_SIZE = 256
176
+ end
168
177
  else
169
178
  DEFAULT_POOL_SIZE = 256
170
179
  end
@@ -172,7 +181,7 @@ class Net::HTTP::Persistent
172
181
  ##
173
182
  # The version of Net::HTTP::Persistent you are using
174
183
 
175
- VERSION = '4.0.1'
184
+ VERSION = '4.0.3'
176
185
 
177
186
  ##
178
187
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -447,6 +456,21 @@ class Net::HTTP::Persistent
447
456
 
448
457
  attr_reader :verify_mode
449
458
 
459
+ ##
460
+ # HTTPS verify_hostname.
461
+ #
462
+ # If a client sets this to true and enables SNI with SSLSocket#hostname=,
463
+ # the hostname verification on the server certificate is performed
464
+ # automatically during the handshake using
465
+ # OpenSSL::SSL.verify_certificate_identity().
466
+ #
467
+ # You can set +verify_hostname+ as true to use hostname verification
468
+ # during the handshake.
469
+ #
470
+ # NOTE: This works with Ruby > 3.0.
471
+
472
+ attr_reader :verify_hostname
473
+
450
474
  ##
451
475
  # Creates a new Net::HTTP::Persistent.
452
476
  #
@@ -506,6 +530,7 @@ class Net::HTTP::Persistent
506
530
  @verify_callback = nil
507
531
  @verify_depth = nil
508
532
  @verify_mode = nil
533
+ @verify_hostname = nil
509
534
  @cert_store = nil
510
535
 
511
536
  @generation = 0 # incremented when proxy URI changes
@@ -605,13 +630,23 @@ class Net::HTTP::Persistent
605
630
 
606
631
  return yield connection
607
632
  rescue Errno::ECONNREFUSED
608
- address = http.proxy_address || http.address
609
- port = http.proxy_port || http.port
633
+ if http.proxy?
634
+ address = http.proxy_address
635
+ port = http.proxy_port
636
+ else
637
+ address = http.address
638
+ port = http.port
639
+ end
610
640
 
611
641
  raise Error, "connection refused: #{address}:#{port}"
612
642
  rescue Errno::EHOSTDOWN
613
- address = http.proxy_address || http.address
614
- port = http.proxy_port || http.port
643
+ if http.proxy?
644
+ address = http.proxy_address
645
+ port = http.proxy_port
646
+ else
647
+ address = http.address
648
+ port = http.port
649
+ end
615
650
 
616
651
  raise Error, "host down: #{address}:#{port}"
617
652
  ensure
@@ -710,7 +745,7 @@ class Net::HTTP::Persistent
710
745
  # block is given. Returns all responses received.
711
746
  #
712
747
  # See
713
- # Net::HTTP::Pipeline[http://docs.seattlerb.org/net-http-pipeline/Net/HTTP/Pipeline.html]
748
+ # Net::HTTP::Pipeline[https://rdoc.info/gems/net-http-pipeline/Net/HTTP/Pipeline]
714
749
  # for further details.
715
750
  #
716
751
  # Only if <tt>net-http-pipeline</tt> was required before
@@ -963,8 +998,10 @@ class Net::HTTP::Persistent
963
998
  connection.min_version = @min_version if @min_version
964
999
  connection.max_version = @max_version if @max_version
965
1000
 
966
- connection.verify_depth = @verify_depth
967
- connection.verify_mode = @verify_mode
1001
+ connection.verify_depth = @verify_depth
1002
+ connection.verify_mode = @verify_mode
1003
+ connection.verify_hostname = @verify_hostname if
1004
+ @verify_hostname && connection.respond_to?(:verify_hostname=)
968
1005
 
969
1006
  if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
970
1007
  not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
@@ -1073,6 +1110,15 @@ application:
1073
1110
  reconnect_ssl
1074
1111
  end
1075
1112
 
1113
+ ##
1114
+ # Sets the HTTPS verify_hostname. Defaults to false.
1115
+
1116
+ def verify_hostname= verify_hostname
1117
+ @verify_hostname = verify_hostname
1118
+
1119
+ reconnect_ssl
1120
+ end
1121
+
1076
1122
  ##
1077
1123
  # SSL verification callback.
1078
1124
 
@@ -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
@@ -362,6 +365,7 @@ class TestNetHttpPersistent < Minitest::Test
362
365
  end
363
366
 
364
367
  def test_connection_for_finished_ssl
368
+ skip 'Broken on Windows' if Gem.win_platform?
365
369
  skip 'OpenSSL is missing' unless HAVE_OPENSSL
366
370
 
367
371
  uri = URI.parse 'https://example.com/path'
@@ -555,6 +559,7 @@ class TestNetHttpPersistent < Minitest::Test
555
559
  end
556
560
 
557
561
  def test_connection_for_ssl
562
+ skip 'Broken on Windows' if Gem.win_platform?
558
563
  skip 'OpenSSL is missing' unless HAVE_OPENSSL
559
564
 
560
565
  uri = URI.parse 'https://example.com/path'
@@ -595,6 +600,7 @@ class TestNetHttpPersistent < Minitest::Test
595
600
  end
596
601
 
597
602
  def test_connection_for_ssl_case
603
+ skip 'Broken on Windows' if Gem.win_platform?
598
604
  skip 'OpenSSL is missing' unless HAVE_OPENSSL
599
605
 
600
606
  uri = URI.parse 'HTTPS://example.com/path'
@@ -631,6 +637,7 @@ class TestNetHttpPersistent < Minitest::Test
631
637
  end
632
638
 
633
639
  def test_expired_eh
640
+ skip 'Broken on Windows' if Gem.win_platform?
634
641
  c = basic_connection
635
642
  c.requests = 0
636
643
  c.last_use = Time.now - 11
@@ -976,7 +983,10 @@ class TestNetHttpPersistent < Minitest::Test
976
983
  assert_equal 'keep-alive', req['connection']
977
984
  assert_equal '30', req['keep-alive']
978
985
 
979
- assert_in_delta Time.now, c.last_use
986
+ # There's some roounding issue on jruby preventing this from passing
987
+ unless RUBY_PLATFORM == "java"
988
+ assert_in_delta Time.now, c.last_use
989
+ end
980
990
 
981
991
  assert_equal 1, c.requests
982
992
  end
@@ -1249,6 +1259,7 @@ class TestNetHttpPersistent < Minitest::Test
1249
1259
  assert_equal OpenSSL::SSL::VERIFY_PEER, c.verify_mode
1250
1260
  assert_kind_of OpenSSL::X509::Store, c.cert_store
1251
1261
  assert_nil c.verify_callback
1262
+ assert_nil c.verify_hostname if c.respond_to?(:verify_hostname)
1252
1263
  end
1253
1264
 
1254
1265
  def test_ssl_ca_file
@@ -1332,6 +1343,21 @@ class TestNetHttpPersistent < Minitest::Test
1332
1343
  assert_equal OpenSSL::SSL::VERIFY_NONE, c.verify_mode
1333
1344
  end
1334
1345
 
1346
+ def test_ssl_verify_hostname
1347
+ skip 'OpenSSL is missing' unless HAVE_OPENSSL
1348
+
1349
+ @http.verify_hostname = true
1350
+ c = Net::HTTP.new 'localhost', 80
1351
+
1352
+ skip 'net/http doesn\'t provide verify_hostname= method' unless
1353
+ c.respond_to?(:verify_hostname=)
1354
+
1355
+ @http.ssl c
1356
+
1357
+ assert c.use_ssl?
1358
+ assert c.verify_hostname
1359
+ end
1360
+
1335
1361
  def test_ssl_warning
1336
1362
  skip 'OpenSSL is missing' unless HAVE_OPENSSL
1337
1363
 
@@ -1437,5 +1463,15 @@ class TestNetHttpPersistent < Minitest::Test
1437
1463
  assert_equal 1, @http.ssl_generation
1438
1464
  end
1439
1465
 
1466
+ def test_connection_pool_after_fork
1467
+ # ConnectionPool 2.4+ calls `checkin(force: true)` after fork
1468
+ @http.pool.checkin(force: true)
1469
+
1470
+ @http.pool.checkout ['example.com', 80, nil, nil, nil, nil]
1471
+ @http.pool.checkin(force: true)
1472
+ @http.pool.reload do |connection|
1473
+ connection.close
1474
+ end
1475
+ end
1440
1476
  end
1441
1477
 
@@ -57,7 +57,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
57
57
  @stack.pop timeout: 0
58
58
  end
59
59
 
60
- assert_equal 'Waited 0 sec', e.message
60
+ assert_match 'Waited 0 sec', e.message
61
61
  end
62
62
 
63
63
  def test_pop_full
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.1
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
10
+ date: 2024-09-09 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: connection_pool
@@ -24,88 +23,6 @@ dependencies:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: '2.2'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '5.14'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '5.14'
41
- - !ruby/object:Gem::Dependency
42
- name: hoe-bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.5'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.5'
55
- - !ruby/object:Gem::Dependency
56
- name: hoe-travis
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.4'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 1.4.1
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '1.4'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 1.4.1
75
- - !ruby/object:Gem::Dependency
76
- name: rdoc
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '4.0'
82
- - - "<"
83
- - !ruby/object:Gem::Version
84
- version: '7'
85
- type: :development
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '4.0'
92
- - - "<"
93
- - !ruby/object:Gem::Version
94
- version: '7'
95
- - !ruby/object:Gem::Dependency
96
- name: hoe
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '3.22'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: '3.22'
109
26
  description: |-
110
27
  Manages persistent connections using Net::HTTP including a thread pool for
111
28
  connecting to multiple hosts.
@@ -129,7 +46,6 @@ extra_rdoc_files:
129
46
  files:
130
47
  - ".autotest"
131
48
  - ".gemtest"
132
- - ".travis.yml"
133
49
  - Gemfile
134
50
  - History.txt
135
51
  - Manifest.txt
@@ -146,7 +62,6 @@ licenses:
146
62
  - MIT
147
63
  metadata:
148
64
  homepage_uri: https://github.com/drbrain/net-http-persistent
149
- post_install_message:
150
65
  rdoc_options:
151
66
  - "--main"
152
67
  - README.rdoc
@@ -156,15 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
71
  requirements:
157
72
  - - ">="
158
73
  - !ruby/object:Gem::Version
159
- version: '2.3'
74
+ version: '2.4'
160
75
  required_rubygems_version: !ruby/object:Gem::Requirement
161
76
  requirements:
162
77
  - - ">="
163
78
  - !ruby/object:Gem::Version
164
79
  version: '0'
165
80
  requirements: []
166
- rubygems_version: 3.1.4
167
- signing_key:
81
+ rubygems_version: 3.6.0.dev
168
82
  specification_version: 4
169
83
  summary: Manages persistent connections using Net::HTTP including a thread pool for
170
84
  connecting to multiple hosts
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- ---
2
- after_script:
3
- - rake travis:after -t
4
- before_script:
5
- - gem install hoe-travis --no-document
6
- - rake travis:before -t
7
- language: ruby
8
- notifications:
9
- email:
10
- - drbrain@segment7.net
11
- rvm:
12
- - 2.3
13
- - 2.4
14
- - 2.5
15
- - 2.6
16
- - 2.7
17
- script: rake travis
18
- install: "" # avoid running default bundler install
19
-
20
- matrix:
21
- include:
22
- - rvm: "2.7"
23
- env: TRAVIS_MATRIX=pipeline