net-http-persistent 2.9.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of net-http-persistent might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.travis.yml +15 -0
- data/History.txt +19 -0
- data/Manifest.txt +5 -3
- data/Rakefile +4 -1
- data/lib/net/http/persistent.rb +195 -273
- data/lib/net/http/persistent/connection.rb +40 -0
- data/lib/net/http/persistent/pool.rb +46 -0
- data/lib/net/http/persistent/timed_stack_multi.rb +69 -0
- data/test/test_net_http_persistent.rb +384 -542
- data/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
- metadata +40 -27
- metadata.gz.sig +0 -0
- data/lib/net/http/faster.rb +0 -27
- data/lib/net/http/persistent/ssl_reuse.rb +0 -129
- data/test/test_net_http_persistent_ssl_reuse.rb +0 -112
@@ -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_equal '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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http-persistent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDNjCCAh6gAwIBAgIBBDANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
|
14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
|
+
2u6n3qOEsaxIfwYcU4lCgeZ61JdVU+WWK+GfZpCz4BnjA5hgwdFaf5Zb560RtW7S
|
28
|
+
77pi/SZtblyK/jqz1hgoMcaYZvIJTqZnen0pHaq+lKY1KzGdTuVbwD3DO+Fi1Vu8
|
29
|
+
BOJAX2VNKk4wthxdCu0SvPe7e+QMP2rmaZOyuX4ztiDQiGuoJxyeqoG1WiOttINU
|
30
|
+
U76tHMFuL0FUYw==
|
32
31
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
32
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
34
33
|
dependencies:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: connection_pool
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: minitest
|
37
50
|
requirement: !ruby/object:Gem::Requirement
|
38
51
|
requirements:
|
39
52
|
- - "~>"
|
40
53
|
- !ruby/object:Gem::Version
|
41
|
-
version: '5.
|
54
|
+
version: '5.8'
|
42
55
|
type: :development
|
43
56
|
prerelease: false
|
44
57
|
version_requirements: !ruby/object:Gem::Requirement
|
45
58
|
requirements:
|
46
59
|
- - "~>"
|
47
60
|
- !ruby/object:Gem::Version
|
48
|
-
version: '5.
|
61
|
+
version: '5.8'
|
49
62
|
- !ruby/object:Gem::Dependency
|
50
63
|
name: rdoc
|
51
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,14 +79,14 @@ dependencies:
|
|
66
79
|
requirements:
|
67
80
|
- - "~>"
|
68
81
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
82
|
+
version: '3.15'
|
70
83
|
type: :development
|
71
84
|
prerelease: false
|
72
85
|
version_requirements: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
87
|
- - "~>"
|
75
88
|
- !ruby/object:Gem::Version
|
76
|
-
version: '3.
|
89
|
+
version: '3.15'
|
77
90
|
description: |-
|
78
91
|
Manages persistent connections using Net::HTTP plus a speed fix for Ruby 1.8.
|
79
92
|
It's thread-safe too!
|
@@ -96,15 +109,17 @@ extra_rdoc_files:
|
|
96
109
|
files:
|
97
110
|
- ".autotest"
|
98
111
|
- ".gemtest"
|
112
|
+
- ".travis.yml"
|
99
113
|
- History.txt
|
100
114
|
- Manifest.txt
|
101
115
|
- README.rdoc
|
102
116
|
- Rakefile
|
103
|
-
- lib/net/http/faster.rb
|
104
117
|
- lib/net/http/persistent.rb
|
105
|
-
- lib/net/http/persistent/
|
118
|
+
- lib/net/http/persistent/connection.rb
|
119
|
+
- lib/net/http/persistent/pool.rb
|
120
|
+
- lib/net/http/persistent/timed_stack_multi.rb
|
106
121
|
- test/test_net_http_persistent.rb
|
107
|
-
- test/
|
122
|
+
- test/test_net_http_persistent_timed_stack_multi.rb
|
108
123
|
homepage: http://docs.seattlerb.org/net-http-persistent
|
109
124
|
licenses:
|
110
125
|
- MIT
|
@@ -117,21 +132,19 @@ require_paths:
|
|
117
132
|
- lib
|
118
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
134
|
requirements:
|
120
|
-
- - "
|
135
|
+
- - "~>"
|
121
136
|
- !ruby/object:Gem::Version
|
122
|
-
version: '
|
137
|
+
version: '2.1'
|
123
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
139
|
requirements:
|
125
140
|
- - ">="
|
126
141
|
- !ruby/object:Gem::Version
|
127
142
|
version: '0'
|
128
143
|
requirements: []
|
129
|
-
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.6.4
|
131
146
|
signing_key:
|
132
147
|
specification_version: 4
|
133
148
|
summary: Manages persistent connections using Net::HTTP plus a speed fix for Ruby
|
134
149
|
1.8
|
135
|
-
test_files:
|
136
|
-
- test/test_net_http_persistent.rb
|
137
|
-
- test/test_net_http_persistent_ssl_reuse.rb
|
150
|
+
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/net/http/faster.rb
DELETED
@@ -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
|
-
|