net-http-persistent 2.9.4 → 4.0.2

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.
@@ -0,0 +1,151 @@
1
+ require 'minitest/autorun'
2
+ require 'net/http/persistent'
3
+
4
+ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
5
+
6
+ class Connection
7
+ attr_reader :host
8
+
9
+ def initialize(host)
10
+ @host = host
11
+ end
12
+ end
13
+
14
+ def setup
15
+ @stack = Net::HTTP::Persistent::TimedStackMulti.new { Object.new }
16
+ end
17
+
18
+ def test_empty_eh
19
+ stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { Object.new }
20
+
21
+ refute_empty stack
22
+
23
+ popped = stack.pop
24
+
25
+ assert_empty stack
26
+
27
+ stack.push connection_args: popped
28
+
29
+ refute_empty stack
30
+ end
31
+
32
+ def test_length
33
+ stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { Object.new }
34
+
35
+ assert_equal 1, stack.length
36
+
37
+ popped = stack.pop
38
+
39
+ assert_equal 0, stack.length
40
+
41
+ stack.push connection_args: popped
42
+
43
+ assert_equal 1, stack.length
44
+ end
45
+
46
+ def test_pop
47
+ object = Object.new
48
+ @stack.push object
49
+
50
+ popped = @stack.pop
51
+
52
+ assert_same object, popped
53
+ end
54
+
55
+ def test_pop_empty
56
+ e = assert_raises Timeout::Error do
57
+ @stack.pop timeout: 0
58
+ end
59
+
60
+ assert_match 'Waited 0 sec', e.message
61
+ end
62
+
63
+ def test_pop_full
64
+ stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { Object.new }
65
+
66
+ popped = stack.pop
67
+
68
+ refute_nil popped
69
+ assert_empty stack
70
+ end
71
+
72
+ def test_pop_wait
73
+ thread = Thread.start do
74
+ @stack.pop
75
+ end
76
+
77
+ Thread.pass while thread.status == 'run'
78
+
79
+ object = Object.new
80
+
81
+ @stack.push object
82
+
83
+ assert_same object, thread.value
84
+ end
85
+
86
+ def test_pop_shutdown
87
+ @stack.shutdown { }
88
+
89
+ assert_raises ConnectionPool::PoolShuttingDownError do
90
+ @stack.pop
91
+ end
92
+ end
93
+
94
+ def test_push
95
+ stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { Object.new }
96
+
97
+ conn = stack.pop
98
+
99
+ stack.push connection_args: conn
100
+
101
+ refute_empty stack
102
+ end
103
+
104
+ def test_push_shutdown
105
+ called = []
106
+
107
+ @stack.shutdown do |object|
108
+ called << object
109
+ end
110
+
111
+ @stack.push connection_args: Object.new
112
+
113
+ refute_empty called
114
+ assert_empty @stack
115
+ end
116
+
117
+ def test_shutdown
118
+ @stack.push connection_args: Object.new
119
+
120
+ called = []
121
+
122
+ @stack.shutdown do |object|
123
+ called << object
124
+ end
125
+
126
+ refute_empty called
127
+ assert_empty @stack
128
+ end
129
+
130
+ def test_pop_recycle
131
+ stack = Net::HTTP::Persistent::TimedStackMulti.new(2) { |host| Connection.new(host) }
132
+
133
+ a_conn = stack.pop connection_args: 'a.example'
134
+ stack.push a_conn, connection_args: 'a.example'
135
+
136
+ b_conn = stack.pop connection_args: 'b.example'
137
+ stack.push b_conn, connection_args: 'b.example'
138
+
139
+ c_conn = stack.pop connection_args: 'c.example'
140
+
141
+ assert_equal 'c.example', c_conn.host
142
+
143
+ stack.push c_conn, connection_args: 'c.example'
144
+
145
+ recreated = stack.pop connection_args: 'a.example'
146
+
147
+ refute_same a_conn, recreated
148
+ end
149
+
150
+ end
151
+
metadata CHANGED
@@ -1,90 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-persistent
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.4
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
14
- YWluMR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FVznDcHiSFybGKBa5n25Egql1t
30
- KDyY1VIazVgoC8XvR4h/95/iScPiuglzA+DBG1hip1xScAtw05BrXyUNrc9CEMYU
31
- wgF94UVoHRp6ywo8I7NP3HcwFQDFNEZPNGXsng==
32
- -----END CERTIFICATE-----
33
- date: 2014-02-10 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2023-03-29 00:00:00.000000000 Z
34
12
  dependencies:
35
13
  - !ruby/object:Gem::Dependency
36
- name: minitest
14
+ name: connection_pool
37
15
  requirement: !ruby/object:Gem::Requirement
38
16
  requirements:
39
17
  - - "~>"
40
18
  - !ruby/object:Gem::Version
41
- version: '5.2'
42
- type: :development
19
+ version: '2.2'
20
+ type: :runtime
43
21
  prerelease: false
44
22
  version_requirements: !ruby/object:Gem::Requirement
45
23
  requirements:
46
24
  - - "~>"
47
25
  - !ruby/object:Gem::Version
48
- version: '5.2'
49
- - !ruby/object:Gem::Dependency
50
- name: rdoc
51
- requirement: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '4.0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '4.0'
63
- - !ruby/object:Gem::Dependency
64
- name: hoe
65
- requirement: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '3.7'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '3.7'
26
+ version: '2.2'
77
27
  description: |-
78
- Manages persistent connections using Net::HTTP plus a speed fix for Ruby 1.8.
79
- It's thread-safe too!
28
+ Manages persistent connections using Net::HTTP including a thread pool for
29
+ connecting to multiple hosts.
80
30
 
81
31
  Using persistent HTTP connections can dramatically increase the speed of HTTP.
82
32
  Creating a new HTTP connection for every request involves an extra TCP
83
33
  round-trip and causes TCP congestion avoidance negotiation to start over.
84
34
 
85
35
  Net::HTTP supports persistent connections with some API methods but does not
86
- handle reconnection gracefully. Net::HTTP::Persistent supports reconnection
87
- and retry according to RFC 2616.
36
+ make setting up a single persistent connection or managing multiple
37
+ connections easy. Net::HTTP::Persistent wraps Net::HTTP and allows you to
38
+ focus on how to make HTTP requests.
88
39
  email:
89
40
  - drbrain@segment7.net
90
41
  executables: []
@@ -96,19 +47,22 @@ extra_rdoc_files:
96
47
  files:
97
48
  - ".autotest"
98
49
  - ".gemtest"
50
+ - Gemfile
99
51
  - History.txt
100
52
  - Manifest.txt
101
53
  - README.rdoc
102
54
  - Rakefile
103
- - lib/net/http/faster.rb
104
55
  - lib/net/http/persistent.rb
105
- - lib/net/http/persistent/ssl_reuse.rb
56
+ - lib/net/http/persistent/connection.rb
57
+ - lib/net/http/persistent/pool.rb
58
+ - lib/net/http/persistent/timed_stack_multi.rb
106
59
  - test/test_net_http_persistent.rb
107
- - test/test_net_http_persistent_ssl_reuse.rb
108
- homepage: http://docs.seattlerb.org/net-http-persistent
60
+ - test/test_net_http_persistent_timed_stack_multi.rb
61
+ homepage: https://github.com/drbrain/net-http-persistent
109
62
  licenses:
110
63
  - MIT
111
- metadata: {}
64
+ metadata:
65
+ homepage_uri: https://github.com/drbrain/net-http-persistent
112
66
  post_install_message:
113
67
  rdoc_options:
114
68
  - "--main"
@@ -119,19 +73,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
73
  requirements:
120
74
  - - ">="
121
75
  - !ruby/object:Gem::Version
122
- version: '0'
76
+ version: '2.4'
123
77
  required_rubygems_version: !ruby/object:Gem::Requirement
124
78
  requirements:
125
79
  - - ">="
126
80
  - !ruby/object:Gem::Version
127
81
  version: '0'
128
82
  requirements: []
129
- rubyforge_project: net-http-persistent
130
- rubygems_version: 2.2.1
83
+ rubygems_version: 3.0.3.1
131
84
  signing_key:
132
85
  specification_version: 4
133
- summary: Manages persistent connections using Net::HTTP plus a speed fix for Ruby
134
- 1.8
135
- test_files:
136
- - test/test_net_http_persistent.rb
137
- - test/test_net_http_persistent_ssl_reuse.rb
86
+ summary: Manages persistent connections using Net::HTTP including a thread pool for
87
+ connecting to multiple hosts
88
+ test_files: []
checksums.yaml.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- .Nj�^K�^;Y�Q�-_�Q�a�Jm�cݭ���|���t�W� P��A{��X��'5�]1��]Ǵt���H�ҫu�Y���
2
- ?�
@@ -1,27 +0,0 @@
1
- require 'net/protocol'
2
-
3
- ##
4
- # Aaron Patterson's monkeypatch (accepted into 1.9.1) to fix Net::HTTP's speed
5
- # problems.
6
- #
7
- # http://gist.github.com/251244
8
-
9
- class Net::BufferedIO #:nodoc:
10
- alias :old_rbuf_fill :rbuf_fill
11
-
12
- def rbuf_fill
13
- if @io.respond_to? :read_nonblock then
14
- begin
15
- @rbuf << @io.read_nonblock(65536)
16
- rescue Errno::EWOULDBLOCK, Errno::EAGAIN => e
17
- retry if IO.select [@io], nil, nil, @read_timeout
18
- raise Timeout::Error, e.message
19
- end
20
- else # SSL sockets do not have read_nonblock
21
- timeout @read_timeout do
22
- @rbuf << @io.sysread(65536)
23
- end
24
- end
25
- end
26
- end if RUBY_VERSION < '1.9'
27
-
@@ -1,129 +0,0 @@
1
- ##
2
- # This Net::HTTP subclass adds SSL session reuse and Server Name Indication
3
- # (SNI) RFC 3546.
4
- #
5
- # DO NOT DEPEND UPON THIS CLASS
6
- #
7
- # This class is an implementation detail and is subject to change or removal
8
- # at any time.
9
-
10
- class Net::HTTP::Persistent::SSLReuse < Net::HTTP
11
-
12
- @is_proxy_class = false
13
- @proxy_addr = nil
14
- @proxy_port = nil
15
- @proxy_user = nil
16
- @proxy_pass = nil
17
-
18
- def initialize address, port = nil # :nodoc:
19
- super
20
-
21
- @ssl_session = nil
22
- end
23
-
24
- ##
25
- # From ruby trunk r33086 including http://redmine.ruby-lang.org/issues/5341
26
-
27
- def connect # :nodoc:
28
- D "opening connection to #{conn_address()}..."
29
- s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
30
- D "opened"
31
- if use_ssl?
32
- ssl_parameters = Hash.new
33
- iv_list = instance_variables
34
- SSL_ATTRIBUTES.each do |name|
35
- ivname = "@#{name}".intern
36
- if iv_list.include?(ivname) and
37
- value = instance_variable_get(ivname)
38
- ssl_parameters[name] = value
39
- end
40
- end
41
- unless @ssl_context then
42
- @ssl_context = OpenSSL::SSL::SSLContext.new
43
- @ssl_context.set_params(ssl_parameters)
44
- end
45
- s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
46
- s.sync_close = true
47
- end
48
- @socket = Net::BufferedIO.new(s)
49
- @socket.read_timeout = @read_timeout
50
- @socket.continue_timeout = @continue_timeout if
51
- @socket.respond_to? :continue_timeout
52
- @socket.debug_output = @debug_output
53
- if use_ssl?
54
- begin
55
- if proxy?
56
- @socket.writeline sprintf('CONNECT %s:%s HTTP/%s',
57
- @address, @port, HTTPVersion)
58
- @socket.writeline "Host: #{@address}:#{@port}"
59
- if proxy_user
60
- credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
61
- credential.delete!("\r\n")
62
- @socket.writeline "Proxy-Authorization: Basic #{credential}"
63
- end
64
- @socket.writeline ''
65
- Net::HTTPResponse.read_new(@socket).value
66
- end
67
- s.session = @ssl_session if @ssl_session
68
- # Server Name Indication (SNI) RFC 3546
69
- s.hostname = @address if s.respond_to? :hostname=
70
- timeout(@open_timeout) { s.connect }
71
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
72
- s.post_connection_check(@address)
73
- end
74
- @ssl_session = s.session
75
- rescue => exception
76
- D "Conn close because of connect error #{exception}"
77
- @socket.close if @socket and not @socket.closed?
78
- raise exception
79
- end
80
- end
81
- on_connect
82
- end if RUBY_VERSION > '1.9'
83
-
84
- ##
85
- # From ruby_1_8_7 branch r29865 including a modified
86
- # http://redmine.ruby-lang.org/issues/5341
87
-
88
- def connect # :nodoc:
89
- D "opening connection to #{conn_address()}..."
90
- s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
91
- D "opened"
92
- if use_ssl?
93
- unless @ssl_context.verify_mode
94
- warn "warning: peer certificate won't be verified in this SSL session"
95
- @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
96
- end
97
- s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
98
- s.sync_close = true
99
- end
100
- @socket = Net::BufferedIO.new(s)
101
- @socket.read_timeout = @read_timeout
102
- @socket.debug_output = @debug_output
103
- if use_ssl?
104
- if proxy?
105
- @socket.writeline sprintf('CONNECT %s:%s HTTP/%s',
106
- @address, @port, HTTPVersion)
107
- @socket.writeline "Host: #{@address}:#{@port}"
108
- if proxy_user
109
- credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
110
- credential.delete!("\r\n")
111
- @socket.writeline "Proxy-Authorization: Basic #{credential}"
112
- end
113
- @socket.writeline ''
114
- Net::HTTPResponse.read_new(@socket).value
115
- end
116
- s.session = @ssl_session if @ssl_session
117
- s.connect
118
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
119
- s.post_connection_check(@address)
120
- end
121
- @ssl_session = s.session
122
- end
123
- on_connect
124
- end if RUBY_VERSION < '1.9'
125
-
126
- private :connect
127
-
128
- end
129
-
@@ -1,112 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'net/http/persistent'
4
- have_ssl =
5
- begin
6
- require 'openssl'
7
- require 'webrick'
8
- require 'webrick/ssl'
9
- true
10
- rescue LoadError
11
- false
12
- end
13
-
14
- ##
15
- # This test is based on (and contains verbatim code from) the Net::HTTP tests
16
- # in ruby
17
-
18
- class TestNetHttpPersistentSSLReuse < Minitest::Test
19
-
20
- class NullWriter
21
- def <<(s) end
22
- def puts(*args) end
23
- def print(*args) end
24
- def printf(*args) end
25
- end
26
-
27
- def setup
28
- @name = OpenSSL::X509::Name.parse 'CN=localhost/DC=localdomain'
29
-
30
- @key = OpenSSL::PKey::RSA.new 1024
31
-
32
- @cert = OpenSSL::X509::Certificate.new
33
- @cert.version = 2
34
- @cert.serial = 0
35
- @cert.not_before = Time.now
36
- @cert.not_after = Time.now + 300
37
- @cert.public_key = @key.public_key
38
- @cert.subject = @name
39
- @cert.issuer = @name
40
-
41
- @cert.sign @key, OpenSSL::Digest::SHA1.new
42
-
43
- @host = 'localhost'
44
- @port = 10082
45
-
46
- config = {
47
- :BindAddress => @host,
48
- :Port => @port,
49
- :Logger => WEBrick::Log.new(NullWriter.new),
50
- :AccessLog => [],
51
- :ShutDownSocketWithoutClose => true,
52
- :ServerType => Thread,
53
- :SSLEnable => true,
54
- :SSLCertificate => @cert,
55
- :SSLPrivateKey => @key,
56
- :SSLStartImmediately => true,
57
- }
58
-
59
- @server = WEBrick::HTTPServer.new config
60
-
61
- @server.mount_proc '/' do |req, res|
62
- res.body = "ok"
63
- end
64
-
65
- @server.start
66
-
67
- begin
68
- TCPSocket.open(@host, @port).close
69
- rescue Errno::ECONNREFUSED
70
- sleep 0.2
71
- n_try_max -= 1
72
- raise 'cannot spawn server; give up' if n_try_max < 0
73
- retry
74
- end
75
- end
76
-
77
- def teardown
78
- if @server then
79
- @server.shutdown
80
- sleep 0.01 until @server.status == :Stop
81
- end
82
- end
83
-
84
- def test_ssl_connection_reuse
85
- store = OpenSSL::X509::Store.new
86
- store.add_cert @cert
87
-
88
- @http = Net::HTTP::Persistent::SSLReuse.new @host, @port
89
- @http.cert_store = store
90
- @http.ssl_version = :SSLv3 if @http.respond_to? :ssl_version=
91
- @http.use_ssl = true
92
- @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
93
-
94
- @http.start
95
- @http.get '/'
96
- @http.finish
97
-
98
- @http.start
99
- @http.get '/'
100
- @http.finish
101
-
102
- @http.start
103
- @http.get '/'
104
-
105
- socket = @http.instance_variable_get :@socket
106
- ssl_socket = socket.io
107
-
108
- assert ssl_socket.session_reused?
109
- end
110
-
111
- end if have_ssl
112
-
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file