net-http-persistent 2.9.4 → 4.0.1
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 +5 -5
- data/.travis.yml +23 -0
- data/Gemfile +15 -0
- data/History.txt +101 -0
- data/Manifest.txt +6 -3
- data/README.rdoc +10 -10
- data/Rakefile +11 -4
- data/lib/net/http/persistent.rb +282 -425
- data/lib/net/http/persistent/connection.rb +40 -0
- data/lib/net/http/persistent/pool.rb +53 -0
- data/lib/net/http/persistent/timed_stack_multi.rb +79 -0
- data/test/test_net_http_persistent.rb +399 -691
- data/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
- metadata +85 -51
- checksums.yaml.gz.sig +0 -2
- data.tar.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
- metadata.gz.sig +0 -0
@@ -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,90 +1,123 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http-persistent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
-
|
12
|
-
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
|
14
|
-
YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
|
15
|
-
ZXQwHhcNMTMwMjI4MDUyMjA4WhcNMTQwMjI4MDUyMjA4WjBBMRAwDgYDVQQDDAdk
|
16
|
-
cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
|
17
|
-
FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
|
18
|
-
LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
|
19
|
-
U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
|
20
|
-
Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
|
21
|
-
mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
|
22
|
-
g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
|
23
|
-
sCANiQ8BAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
24
|
-
BBS5k4Z75VSpdM0AclG2UvzFA/VW5DAfBgNVHREEGDAWgRRkcmJyYWluQHNlZ21l
|
25
|
-
bnQ3Lm5ldDAfBgNVHRIEGDAWgRRkcmJyYWluQHNlZ21lbnQ3Lm5ldDANBgkqhkiG
|
26
|
-
9w0BAQUFAAOCAQEAOflo4Md5aJF//EetzXIGZ2EI5PzKWX/mMpp7cxFyDcVPtTv0
|
27
|
-
js/6zWrWSbd60W9Kn4ch3nYiATFKhisgeYotDDz2/pb/x1ivJn4vEvs9kYKVvbF8
|
28
|
-
V7MV/O5HDW8Q0pA1SljI6GzcOgejtUMxZCyyyDdbUpyAMdt9UpqTZkZ5z1sicgQk
|
29
|
-
5o2XJ+OhceOIUVqVh1r6DNY5tLVaGJabtBmJAYFVznDcHiSFybGKBa5n25Egql1t
|
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: 2021-01-12 00:00:00.000000000 Z
|
34
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: connection_pool
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
28
|
name: minitest
|
37
29
|
requirement: !ruby/object:Gem::Requirement
|
38
30
|
requirements:
|
39
31
|
- - "~>"
|
40
32
|
- !ruby/object:Gem::Version
|
41
|
-
version: '5.
|
33
|
+
version: '5.14'
|
42
34
|
type: :development
|
43
35
|
prerelease: false
|
44
36
|
version_requirements: !ruby/object:Gem::Requirement
|
45
37
|
requirements:
|
46
38
|
- - "~>"
|
47
39
|
- !ruby/object:Gem::Version
|
48
|
-
version: '5.
|
40
|
+
version: '5.14'
|
49
41
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
42
|
+
name: hoe-bundler
|
51
43
|
requirement: !ruby/object:Gem::Requirement
|
52
44
|
requirements:
|
53
45
|
- - "~>"
|
54
46
|
- !ruby/object:Gem::Version
|
55
|
-
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
|
56
65
|
type: :development
|
57
66
|
prerelease: false
|
58
67
|
version_requirements: !ruby/object:Gem::Requirement
|
59
68
|
requirements:
|
60
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
|
+
- - ">="
|
61
80
|
- !ruby/object:Gem::Version
|
62
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'
|
63
95
|
- !ruby/object:Gem::Dependency
|
64
96
|
name: hoe
|
65
97
|
requirement: !ruby/object:Gem::Requirement
|
66
98
|
requirements:
|
67
99
|
- - "~>"
|
68
100
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
101
|
+
version: '3.22'
|
70
102
|
type: :development
|
71
103
|
prerelease: false
|
72
104
|
version_requirements: !ruby/object:Gem::Requirement
|
73
105
|
requirements:
|
74
106
|
- - "~>"
|
75
107
|
- !ruby/object:Gem::Version
|
76
|
-
version: '3.
|
108
|
+
version: '3.22'
|
77
109
|
description: |-
|
78
|
-
Manages persistent connections using Net::HTTP
|
79
|
-
|
110
|
+
Manages persistent connections using Net::HTTP including a thread pool for
|
111
|
+
connecting to multiple hosts.
|
80
112
|
|
81
113
|
Using persistent HTTP connections can dramatically increase the speed of HTTP.
|
82
114
|
Creating a new HTTP connection for every request involves an extra TCP
|
83
115
|
round-trip and causes TCP congestion avoidance negotiation to start over.
|
84
116
|
|
85
117
|
Net::HTTP supports persistent connections with some API methods but does not
|
86
|
-
|
87
|
-
and
|
118
|
+
make setting up a single persistent connection or managing multiple
|
119
|
+
connections easy. Net::HTTP::Persistent wraps Net::HTTP and allows you to
|
120
|
+
focus on how to make HTTP requests.
|
88
121
|
email:
|
89
122
|
- drbrain@segment7.net
|
90
123
|
executables: []
|
@@ -96,20 +129,24 @@ extra_rdoc_files:
|
|
96
129
|
files:
|
97
130
|
- ".autotest"
|
98
131
|
- ".gemtest"
|
132
|
+
- ".travis.yml"
|
133
|
+
- Gemfile
|
99
134
|
- History.txt
|
100
135
|
- Manifest.txt
|
101
136
|
- README.rdoc
|
102
137
|
- Rakefile
|
103
|
-
- lib/net/http/faster.rb
|
104
138
|
- lib/net/http/persistent.rb
|
105
|
-
- lib/net/http/persistent/
|
139
|
+
- lib/net/http/persistent/connection.rb
|
140
|
+
- lib/net/http/persistent/pool.rb
|
141
|
+
- lib/net/http/persistent/timed_stack_multi.rb
|
106
142
|
- test/test_net_http_persistent.rb
|
107
|
-
- test/
|
108
|
-
homepage:
|
143
|
+
- test/test_net_http_persistent_timed_stack_multi.rb
|
144
|
+
homepage: https://github.com/drbrain/net-http-persistent
|
109
145
|
licenses:
|
110
146
|
- MIT
|
111
|
-
metadata:
|
112
|
-
|
147
|
+
metadata:
|
148
|
+
homepage_uri: https://github.com/drbrain/net-http-persistent
|
149
|
+
post_install_message:
|
113
150
|
rdoc_options:
|
114
151
|
- "--main"
|
115
152
|
- README.rdoc
|
@@ -119,19 +156,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
156
|
requirements:
|
120
157
|
- - ">="
|
121
158
|
- !ruby/object:Gem::Version
|
122
|
-
version: '
|
159
|
+
version: '2.3'
|
123
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
161
|
requirements:
|
125
162
|
- - ">="
|
126
163
|
- !ruby/object:Gem::Version
|
127
164
|
version: '0'
|
128
165
|
requirements: []
|
129
|
-
|
130
|
-
|
131
|
-
signing_key:
|
166
|
+
rubygems_version: 3.1.4
|
167
|
+
signing_key:
|
132
168
|
specification_version: 4
|
133
|
-
summary: Manages persistent connections using Net::HTTP
|
134
|
-
|
135
|
-
test_files:
|
136
|
-
- test/test_net_http_persistent.rb
|
137
|
-
- test/test_net_http_persistent_ssl_reuse.rb
|
169
|
+
summary: Manages persistent connections using Net::HTTP including a thread pool for
|
170
|
+
connecting to multiple hosts
|
171
|
+
test_files: []
|
checksums.yaml.gz.sig
DELETED
data.tar.gz.sig
DELETED
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
|
-
|