glebtv-httpclient 3.2.7 → 3.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/Gemfile +0 -9
- data/Gemfile.lock +34 -258
- data/README.md +1 -0
- data/httpclient.gemspec +1 -2
- data/lib/httpclient/auth.rb +241 -157
- data/lib/httpclient/cacert.p7s +3865 -1911
- data/lib/httpclient/lru_cache.rb +27 -24
- data/lib/httpclient/ssl_config.rb +3 -2
- data/lib/httpclient/version.rb +2 -1
- data/spec/basic_spec.rb +82 -82
- data/spec/cookie_spec.rb +132 -132
- data/spec/hexdump_spec.rb +1 -1
- data/spec/http_message_spec.rb +37 -37
- data/spec/httpclient_spec.rb +267 -263
- data/spec/keepalive_spec.rb +5 -5
- data/spec/lru_spec.rb +5 -11
- data/test/test_auth.rb +29 -2
- metadata +2 -30
data/spec/http_message_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe HTTP::Message do
|
5
5
|
it 'has sane defaults for mime handlers' do
|
6
|
-
HTTP::Message.get_mime_type_func.
|
7
|
-
HTTP::Message.mime_type_handler.
|
6
|
+
expect(HTTP::Message.get_mime_type_func).to be_nil
|
7
|
+
expect(HTTP::Message.mime_type_handler).to be_nil
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'reset' do
|
@@ -13,62 +13,62 @@ describe HTTP::Message do
|
|
13
13
|
HTTP::Message.mime_type_handler = nil
|
14
14
|
end
|
15
15
|
it 'mime type' do
|
16
|
-
HTTP::Message.mime_type('foo.txt').
|
17
|
-
HTTP::Message.mime_type('foo.html').
|
18
|
-
HTTP::Message.mime_type('foo.htm').
|
19
|
-
HTTP::Message.mime_type('foo.doc').
|
20
|
-
HTTP::Message.mime_type('foo.png').
|
21
|
-
HTTP::Message.mime_type('foo.gif').
|
22
|
-
HTTP::Message.mime_type('foo.jpg').
|
23
|
-
HTTP::Message.mime_type('foo.jpeg').
|
24
|
-
HTTP::Message.mime_type('foo.unknown').
|
16
|
+
expect(HTTP::Message.mime_type('foo.txt')).to eq 'text/plain'
|
17
|
+
expect(HTTP::Message.mime_type('foo.html')).to eq 'text/html'
|
18
|
+
expect(HTTP::Message.mime_type('foo.htm')).to eq 'text/html'
|
19
|
+
expect(HTTP::Message.mime_type('foo.doc')).to eq 'application/msword'
|
20
|
+
expect(HTTP::Message.mime_type('foo.png')).to eq 'image/png'
|
21
|
+
expect(HTTP::Message.mime_type('foo.gif')).to eq 'image/gif'
|
22
|
+
expect(HTTP::Message.mime_type('foo.jpg')).to eq 'image/jpeg'
|
23
|
+
expect(HTTP::Message.mime_type('foo.jpeg')).to eq 'image/jpeg'
|
24
|
+
expect(HTTP::Message.mime_type('foo.unknown')).to eq 'application/octet-stream'
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'mime handler' do
|
28
28
|
handler = lambda { |path| 'hello/world' }
|
29
29
|
HTTP::Message.mime_type_handler = handler
|
30
|
-
HTTP::Message.mime_type_handler.
|
30
|
+
expect(HTTP::Message.mime_type_handler).not_to be_nil
|
31
31
|
|
32
|
-
HTTP::Message.get_mime_type_func.
|
32
|
+
expect(HTTP::Message.get_mime_type_func).not_to be_nil
|
33
33
|
|
34
|
-
HTTP::Message.mime_type('foo.txt').
|
34
|
+
expect(HTTP::Message.mime_type('foo.txt')).to eq 'hello/world'
|
35
35
|
|
36
36
|
HTTP::Message.mime_type_handler = nil
|
37
|
-
HTTP::Message.mime_type('foo.txt').
|
37
|
+
expect(HTTP::Message.mime_type('foo.txt')).to eq 'text/plain'
|
38
38
|
HTTP::Message.set_mime_type_func(nil)
|
39
|
-
HTTP::Message.mime_type('foo.txt').
|
39
|
+
expect(HTTP::Message.mime_type('foo.txt')).to eq 'text/plain'
|
40
40
|
|
41
41
|
handler = lambda { |path| nil }
|
42
42
|
HTTP::Message.mime_type_handler = handler
|
43
|
-
HTTP::Message.mime_type('foo.txt').
|
43
|
+
expect(HTTP::Message.mime_type('foo.txt')).to eq 'application/octet-stream'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
|
48
48
|
it 'connect request' do
|
49
49
|
req = HTTP::Message.new_connect_request(urify('https://foo/bar'))
|
50
|
-
req.dump.
|
50
|
+
expect(req.dump).to eq "CONNECT foo:443 HTTP/1.0\r\n\r\n"
|
51
51
|
req = HTTP::Message.new_connect_request(urify('https://example.com/'))
|
52
|
-
req.dump.
|
52
|
+
expect(req.dump).to eq "CONNECT example.com:443 HTTP/1.0\r\n\r\n"
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'response' do
|
56
56
|
res = HTTP::Message.new_response('response')
|
57
57
|
res.contenttype = 'text/plain'
|
58
58
|
res.header.body_date = Time.at(946652400)
|
59
|
-
[
|
59
|
+
expect([
|
60
60
|
"",
|
61
61
|
"Content-Length: 8",
|
62
62
|
"Content-Type: text/plain",
|
63
63
|
"Last-Modified: Fri, 31 Dec 1999 15:00:00 GMT",
|
64
64
|
"Status: 200 OK",
|
65
65
|
"response"
|
66
|
-
].
|
66
|
+
]).to eq res.dump.split(/\r\n/).sort
|
67
67
|
|
68
|
-
res.header['Content-Length'].
|
69
|
-
res.headers['Content-Length'].
|
68
|
+
expect(res.header['Content-Length']).to eq ['8']
|
69
|
+
expect(res.headers['Content-Length']).to eq '8'
|
70
70
|
res.header.set('foo', 'bar')
|
71
|
-
[
|
71
|
+
expect([
|
72
72
|
"",
|
73
73
|
"Content-Length: 8",
|
74
74
|
"Content-Type: text/plain",
|
@@ -76,26 +76,26 @@ describe HTTP::Message do
|
|
76
76
|
"Status: 200 OK",
|
77
77
|
"foo: bar",
|
78
78
|
"response"
|
79
|
-
].
|
79
|
+
]).to eq res.dump.split(/\r\n/).sort
|
80
80
|
|
81
81
|
res = HTTP::Message.new_response(nil)
|
82
|
-
[
|
82
|
+
expect([
|
83
83
|
"Content-Length: 0",
|
84
84
|
"Content-Type: text/html; charset=us-ascii",
|
85
85
|
"Status: 200 OK"
|
86
|
-
].
|
86
|
+
]).to eq res.dump.split(/\r\n/).sort
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'response cookies' do
|
90
90
|
res = HTTP::Message.new_response('response')
|
91
91
|
res.contenttype = 'text/plain'
|
92
92
|
res.header.body_date = Time.at(946652400)
|
93
|
-
res.cookies.
|
93
|
+
expect(res.cookies).to be_nil
|
94
94
|
res.header['Set-Cookie'] = [
|
95
95
|
'CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT',
|
96
96
|
'PART_NUMBER=ROCKET_LAUNCHER_0001; path=/'
|
97
97
|
]
|
98
|
-
[
|
98
|
+
expect([
|
99
99
|
"",
|
100
100
|
"Content-Length: 8",
|
101
101
|
"Content-Type: text/plain",
|
@@ -104,21 +104,21 @@ describe HTTP::Message do
|
|
104
104
|
"Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/",
|
105
105
|
"Status: 200 OK",
|
106
106
|
"response"
|
107
|
-
].
|
107
|
+
]).to eq res.dump.split(/\r\n/).sort
|
108
108
|
|
109
|
-
res.cookies.size.
|
110
|
-
res.cookies[0].name.
|
111
|
-
res.cookies[1].name.
|
109
|
+
expect(res.cookies.size).to eq 2
|
110
|
+
expect(res.cookies[0].name).to eq 'CUSTOMER'
|
111
|
+
expect(res.cookies[1].name).to eq 'PART_NUMBER'
|
112
112
|
end
|
113
113
|
|
114
114
|
it '#ok?' do
|
115
115
|
res = HTTP::Message.new_response('response')
|
116
|
-
res.ok
|
116
|
+
expect(res.ok?).to eq true
|
117
117
|
res.status = 404
|
118
|
-
res.ok
|
118
|
+
expect(res.ok?).to eq false
|
119
119
|
res.status = 500
|
120
|
-
res.ok
|
120
|
+
expect(res.ok?).to eq false
|
121
121
|
res.status = 302
|
122
|
-
res.ok
|
122
|
+
expect(res.ok?).to eq false
|
123
123
|
end
|
124
124
|
end
|
data/spec/httpclient_spec.rb
CHANGED
@@ -10,9 +10,9 @@ describe 'HTTPClient' do
|
|
10
10
|
without_noproxy do
|
11
11
|
@proxy.io.string = ""
|
12
12
|
@client = HTTPClient.new(@proxy.u)
|
13
|
-
@client.proxy.
|
14
|
-
@client.head(@srv.u).status.
|
15
|
-
@proxy.io.string.
|
13
|
+
expect(@client.proxy).to eq(urify(@proxy.u))
|
14
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
15
|
+
expect(@proxy.io.string).to match(/accept/)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -22,8 +22,8 @@ describe 'HTTPClient' do
|
|
22
22
|
@client.debug_dev = str
|
23
23
|
@client.get(@srv.u)
|
24
24
|
lines = str.split(/(?:\r?\n)+/)
|
25
|
-
lines[0].
|
26
|
-
lines[4].
|
25
|
+
expect(lines[0]).to eq("= Request")
|
26
|
+
expect(lines[4]).to match /^User-Agent: agent_name_foo/
|
27
27
|
end
|
28
28
|
|
29
29
|
it "from" do
|
@@ -32,17 +32,17 @@ describe 'HTTPClient' do
|
|
32
32
|
@client.debug_dev = str
|
33
33
|
@client.get(@srv.u)
|
34
34
|
lines = str.split(/(?:\r?\n)+/)
|
35
|
-
lines[0].
|
36
|
-
lines[5].
|
35
|
+
expect(lines[0]).to eq("= Request")
|
36
|
+
expect(lines[5]).to match /^From: from_bar/
|
37
37
|
end
|
38
38
|
|
39
39
|
it "debug dev" do
|
40
40
|
str = ""
|
41
41
|
@client.debug_dev = str
|
42
|
-
@client.debug_dev.object_id.
|
43
|
-
str.empty
|
42
|
+
expect(@client.debug_dev.object_id).to eq(str.object_id)
|
43
|
+
expect(str.empty?).to be_truthy
|
44
44
|
@client.get(@srv.u)
|
45
|
-
str.empty
|
45
|
+
expect(str.empty?).to be_falsey
|
46
46
|
end
|
47
47
|
|
48
48
|
it "debug dev stream" do
|
@@ -52,7 +52,7 @@ describe 'HTTPClient' do
|
|
52
52
|
until conn.finished?
|
53
53
|
Thread.pass
|
54
54
|
end
|
55
|
-
str.empty
|
55
|
+
expect(str.empty?).to be_falsey
|
56
56
|
end
|
57
57
|
|
58
58
|
it "host given" do
|
@@ -60,19 +60,19 @@ describe 'HTTPClient' do
|
|
60
60
|
@client.debug_dev = str
|
61
61
|
@client.get(@srv.u)
|
62
62
|
lines = str.split(/(?:\r?\n)+/)
|
63
|
-
lines[0].
|
64
|
-
lines[2].
|
65
|
-
lines[3].
|
66
|
-
lines[7].
|
63
|
+
expect(lines[0]).to eq("= Request")
|
64
|
+
expect(lines[2]).to eq("! CONNECTION ESTABLISHED")
|
65
|
+
expect(lines[3]).to eq("GET / HTTP/1.1")
|
66
|
+
expect(lines[7]).to eq("Host: localhost:#{@srv.port}")
|
67
67
|
@client.reset_all
|
68
68
|
str = ""
|
69
69
|
@client.debug_dev = str
|
70
70
|
@client.get(@srv.u, nil, "Host" => "foo")
|
71
71
|
lines = str.split(/(?:\r?\n)+/)
|
72
|
-
lines[0].
|
73
|
-
lines[2].
|
74
|
-
lines[3].
|
75
|
-
lines[4].
|
72
|
+
expect(lines[0]).to eq("= Request")
|
73
|
+
expect(lines[2]).to eq("! CONNECTION ESTABLISHED")
|
74
|
+
expect(lines[3]).to eq("GET / HTTP/1.1")
|
75
|
+
expect(lines[4]).to eq("Host: foo")
|
76
76
|
end
|
77
77
|
|
78
78
|
it "redirect returns not modified" do
|
@@ -86,25 +86,25 @@ describe 'HTTPClient' do
|
|
86
86
|
begin
|
87
87
|
@client.proxy = "http://"
|
88
88
|
rescue
|
89
|
-
$!.class.to_s.
|
89
|
+
expect($!.class.to_s).to match(/InvalidURIError/)
|
90
90
|
end
|
91
91
|
@client.proxy = ""
|
92
|
-
@client.proxy.
|
92
|
+
expect(@client.proxy).to be_nil
|
93
93
|
@client.proxy = "http://admin:admin@foo:1234"
|
94
|
-
@client.proxy.
|
94
|
+
expect(@client.proxy).to eq(urify("http://admin:admin@foo:1234"))
|
95
95
|
uri = urify("http://bar:2345")
|
96
96
|
@client.proxy = uri
|
97
|
-
@client.proxy.
|
97
|
+
expect(@client.proxy).to eq(uri)
|
98
98
|
@proxy.io.string = ""
|
99
99
|
@client.proxy = nil
|
100
|
-
@client.head(@srv.u).status.
|
101
|
-
@proxy.io.string.
|
100
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
101
|
+
expect(@proxy.io.string).not_to match(/accept/)
|
102
102
|
@proxy.io.string = ""
|
103
103
|
@client.proxy = @proxy.u
|
104
104
|
@client.debug_dev = str = ""
|
105
|
-
@client.head(@srv.u).status.
|
106
|
-
@proxy.io.string.
|
107
|
-
str.
|
105
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
106
|
+
expect(@proxy.io.string).to match(/accept/)
|
107
|
+
expect(str).to match(/Host: localhost:#{@srv.port}/)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -112,29 +112,29 @@ describe 'HTTPClient' do
|
|
112
112
|
@client.proxy = @proxy.u
|
113
113
|
@client.debug_dev = str = ""
|
114
114
|
@client.test_loopback_http_response << "HTTP/1.0 200 OK\r\n\r\n"
|
115
|
-
@client.head("http://www.example.com/foo").status.
|
116
|
-
(/\r\nHost: www\.example\.com\r\n/ =~ str).
|
115
|
+
expect(@client.head("http://www.example.com/foo").status).to eq(200)
|
116
|
+
expect(/\r\nHost: www\.example\.com\r\n/ =~ str).to be_truthy
|
117
117
|
@client.debug_dev = str = ""
|
118
118
|
@client.test_loopback_http_response << "HTTP/1.0 200 OK\r\n\r\n"
|
119
|
-
@client.head('http://www.example.com:12345/foo').status.
|
120
|
-
str.
|
119
|
+
expect(@client.head('http://www.example.com:12345/foo').status).to eq 200
|
120
|
+
expect(str).to match(/\r\nHost: www\.example\.com:12345\r\n/)
|
121
121
|
end
|
122
122
|
|
123
123
|
it "proxy env" do
|
124
124
|
ClimateControl.modify http_proxy: 'http://admin:admin@foo:1234', NO_PROXY: 'foobar' do
|
125
125
|
client = HTTPClient.new
|
126
|
-
client.proxy.
|
127
|
-
client.no_proxy.
|
126
|
+
expect(client.proxy).to eq(urify("http://admin:admin@foo:1234"))
|
127
|
+
expect(client.no_proxy).to eq("foobar")
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
it "proxy env cgi" do
|
132
132
|
ClimateControl.modify http_proxy: 'http://admin:admin@foo:1234', NO_PROXY: 'foobar', REQUEST_METHOD: 'GET' do
|
133
133
|
client = HTTPClient.new
|
134
|
-
client.proxy.
|
134
|
+
expect(client.proxy).to eq(nil)
|
135
135
|
ClimateControl.modify CGI_HTTP_PROXY: 'http://admin:admin@foo:1234' do
|
136
136
|
client = HTTPClient.new
|
137
|
-
client.proxy.
|
137
|
+
expect(client.proxy).to eq(urify("http://admin:admin@foo:1234"))
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
@@ -142,56 +142,56 @@ describe 'HTTPClient' do
|
|
142
142
|
it "empty proxy env" do
|
143
143
|
ClimateControl.modify http_proxy: '' do
|
144
144
|
client = HTTPClient.new
|
145
|
-
client.proxy.
|
145
|
+
expect(client.proxy).to eq(nil)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
149
|
it "noproxy for localhost" do
|
150
150
|
@proxy.io.string = ""
|
151
151
|
@client.proxy = @proxy.u
|
152
|
-
@client.head(@srv.u).status.
|
153
|
-
@proxy.io.string.
|
152
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
153
|
+
expect(@proxy.io.string).not_to match(/accept/)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "no proxy" do
|
157
157
|
without_noproxy do
|
158
|
-
@client.no_proxy.
|
158
|
+
expect(@client.no_proxy).to eq(nil)
|
159
159
|
@client.no_proxy = "localhost"
|
160
|
-
@client.no_proxy.
|
160
|
+
expect(@client.no_proxy).to eq("localhost")
|
161
161
|
|
162
162
|
@proxy.io.string = ""
|
163
163
|
@client.proxy = nil
|
164
|
-
@client.head(@srv.u).status.
|
165
|
-
@proxy.io.string.
|
164
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
165
|
+
expect(@proxy.io.string).not_to match(/accept/)
|
166
166
|
|
167
167
|
@proxy.io.string = ""
|
168
168
|
@client.proxy = @proxy.u
|
169
|
-
@client.head(@srv.u).status.
|
170
|
-
@proxy.io.string.
|
169
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
170
|
+
expect(@proxy.io.string).not_to match(/accept/)
|
171
171
|
|
172
172
|
@proxy.io.string = ""
|
173
173
|
@client.no_proxy = "foobar"
|
174
174
|
@client.proxy = @proxy.u
|
175
|
-
@client.head(@srv.u).status.
|
176
|
-
@proxy.io.string.
|
175
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
176
|
+
expect(@proxy.io.string).to match(/accept/)
|
177
177
|
|
178
178
|
@proxy.io.string = ""
|
179
179
|
@client.no_proxy = "foobar,localhost:baz"
|
180
180
|
@client.proxy = @proxy.u
|
181
|
-
@client.head(@srv.u).status.
|
182
|
-
@proxy.io.string.
|
181
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
182
|
+
expect(@proxy.io.string).not_to match(/accept/)
|
183
183
|
|
184
184
|
@proxy.io.string = ""
|
185
185
|
@client.no_proxy = "foobar,localhost:443"
|
186
186
|
@client.proxy = @proxy.u
|
187
|
-
@client.head(@srv.u).status.
|
188
|
-
@proxy.io.string.
|
187
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
188
|
+
expect(@proxy.io.string).to match(/accept/)
|
189
189
|
|
190
190
|
@proxy.io.string = ""
|
191
191
|
@client.no_proxy = "foobar,localhost:443:localhost:#{@srv.port},baz"
|
192
192
|
@client.proxy = @proxy.u
|
193
|
-
@client.head(@srv.u).status.
|
194
|
-
@proxy.io.string.
|
193
|
+
expect(@client.head(@srv.u).status).to eq(200)
|
194
|
+
expect(@proxy.io.string).not_to match(/accept/)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -205,22 +205,22 @@ describe 'HTTPClient' do
|
|
205
205
|
it 'via proxy' do
|
206
206
|
@client.no_proxy = ""
|
207
207
|
@client.head("http://www.foo.com")
|
208
|
-
@str.
|
208
|
+
expect(@str).to match(/CONNECT TO localhost/)
|
209
209
|
end
|
210
210
|
it 'no proxy because .foo.com matches with www.foo.com' do
|
211
211
|
@client.no_proxy = ".foo.com"
|
212
212
|
@client.head("http://www.foo.com")
|
213
|
-
@str.
|
213
|
+
expect(@str).to match(/CONNECT TO www.foo.com/)
|
214
214
|
end
|
215
215
|
it 'via proxy because .foo.com does not matche with foo.com' do
|
216
216
|
@client.no_proxy = ".foo.com"
|
217
217
|
@client.head("http://foo.com")
|
218
|
-
@str.
|
218
|
+
expect(@str).to match(/CONNECT TO localhost/)
|
219
219
|
end
|
220
220
|
it 'no proxy because foo.com matches with foo.com' do
|
221
221
|
@client.no_proxy = "foo.com"
|
222
222
|
@client.head("http://foo.com")
|
223
|
-
@str.
|
223
|
+
expect(@str).to match(/CONNECT TO foo.com/)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
@@ -244,9 +244,9 @@ hello
|
|
244
244
|
EOS
|
245
245
|
@client.debug_dev = str = ""
|
246
246
|
@client.set_auth("http://www.example.org/baz/", "admin", "admin")
|
247
|
-
@client.get("http://www.example.org/baz/foo").content.
|
248
|
-
str.
|
249
|
-
str.
|
247
|
+
expect(@client.get("http://www.example.org/baz/foo").content).to eq("hello")
|
248
|
+
expect(str).to match /^Cookie: foo=bar/
|
249
|
+
expect(str).to match /^Authorization: Basic YWRtaW46YWRtaW4=/
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
@@ -271,19 +271,19 @@ Connection: close\r
|
|
271
271
|
\r
|
272
272
|
hello
|
273
273
|
EOS
|
274
|
-
@client.get("https://localhost:17171/baz").content.
|
274
|
+
expect(@client.get("https://localhost:17171/baz").content).to eq("hello")
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
278
|
it "loopback response" do
|
279
279
|
@client.test_loopback_response << "message body 1"
|
280
280
|
@client.test_loopback_response << "message body 2"
|
281
|
-
@client.get_content("http://somewhere").
|
282
|
-
@client.get_content("http://somewhere").
|
281
|
+
expect(@client.get_content("http://somewhere")).to eq("message body 1")
|
282
|
+
expect(@client.get_content("http://somewhere")).to eq("message body 2")
|
283
283
|
@client.debug_dev = str = ""
|
284
284
|
@client.test_loopback_response << "message body 3"
|
285
|
-
@client.get_content("http://somewhere").
|
286
|
-
str.
|
285
|
+
expect(@client.get_content("http://somewhere")).to eq("message body 3")
|
286
|
+
expect(str).to match /message body 3/
|
287
287
|
end
|
288
288
|
|
289
289
|
it "loopback response stream" do
|
@@ -293,12 +293,12 @@ EOS
|
|
293
293
|
until conn.finished?
|
294
294
|
Thread.pass
|
295
295
|
end
|
296
|
-
conn.pop.content.read.
|
296
|
+
expect(conn.pop.content.read).to eq("message body 1")
|
297
297
|
conn = @client.get_async("http://somewhere")
|
298
298
|
until conn.finished?
|
299
299
|
Thread.pass
|
300
300
|
end
|
301
|
-
conn.pop.content.read.
|
301
|
+
expect(conn.pop.content.read).to eq("message body 2")
|
302
302
|
end
|
303
303
|
|
304
304
|
it "loopback http response" do
|
@@ -310,8 +310,8 @@ message body 1"
|
|
310
310
|
content-length: 100
|
311
311
|
|
312
312
|
message body 2"
|
313
|
-
@client.get_content("http://somewhere").
|
314
|
-
@client.get_content("http://somewhere").
|
313
|
+
expect(@client.get_content("http://somewhere")).to eq("message body 1")
|
314
|
+
expect(@client.get_content("http://somewhere")).to eq("message body 2")
|
315
315
|
end
|
316
316
|
|
317
317
|
it "multiline header" do
|
@@ -325,9 +325,9 @@ content-length: 100
|
|
325
325
|
|
326
326
|
message body 1"
|
327
327
|
res = @client.get("http://somewhere")
|
328
|
-
res.content.
|
329
|
-
res.header["x-foo"].
|
330
|
-
res.header["x-bar"].
|
328
|
+
expect(res.content).to eq("message body 1")
|
329
|
+
expect(res.header["x-foo"]).to eq(["XXX YYY"])
|
330
|
+
expect(res.header["x-bar"]).to eq(["XXX YYY"])
|
331
331
|
end
|
332
332
|
|
333
333
|
it "broken header" do
|
@@ -337,7 +337,7 @@ content-length: 100
|
|
337
337
|
|
338
338
|
message body 1"
|
339
339
|
res = @client.get("http://somewhere")
|
340
|
-
res.content.
|
340
|
+
expect(res.content).to eq("message body 1")
|
341
341
|
end
|
342
342
|
|
343
343
|
it "request uri in response" do
|
@@ -345,13 +345,13 @@ message body 1"
|
|
345
345
|
content-length: 100
|
346
346
|
|
347
347
|
message body"
|
348
|
-
@client.get("http://google.com/").header.request_uri.
|
348
|
+
expect(@client.get("http://google.com/").header.request_uri).to eq(urify("http://google.com/"))
|
349
349
|
end
|
350
350
|
|
351
351
|
it "request uri in response when redirect" do
|
352
352
|
expected = urify(@srv.u("hello"))
|
353
|
-
@client.get(@srv.u("redirect1"), :follow_redirect => true).header.request_uri.
|
354
|
-
@client.get(@srv.u("redirect2"), :follow_redirect => true).header.request_uri.
|
353
|
+
expect(@client.get(@srv.u("redirect1"), :follow_redirect => true).header.request_uri).to eq(expected)
|
354
|
+
expect(@client.get(@srv.u("redirect2"), :follow_redirect => true).header.request_uri).to eq(expected)
|
355
355
|
end
|
356
356
|
|
357
357
|
describe "redirect" do
|
@@ -374,7 +374,7 @@ message body"
|
|
374
374
|
|
375
375
|
it 'http -> http is OK' do
|
376
376
|
@client.test_loopback_http_response << @redirect_to_http
|
377
|
-
@client.get_content(@url).
|
377
|
+
expect(@client.get_content(@url)).to eq 'hello'
|
378
378
|
end
|
379
379
|
|
380
380
|
it 'trying to normal endpoint with SSL -> SSL negotiation failure' do
|
@@ -402,25 +402,25 @@ message body"
|
|
402
402
|
end
|
403
403
|
|
404
404
|
it "redirect see other" do
|
405
|
-
@client.post_content(@srv.u("redirect_see_other")).
|
405
|
+
expect(@client.post_content(@srv.u("redirect_see_other"))).to eq("hello")
|
406
406
|
end
|
407
407
|
|
408
408
|
it "redirect relative" do
|
409
409
|
@client.test_loopback_http_response << "HTTP/1.0 302 OK\nLocation: hello\n\n"
|
410
410
|
silent do
|
411
|
-
@client.get_content(@srv.u('redirect1')).
|
411
|
+
expect(@client.get_content(@srv.u('redirect1'))).to eq 'hello'
|
412
412
|
end
|
413
413
|
|
414
414
|
@client.reset_all
|
415
415
|
@client.redirect_uri_callback = @client.method(:strict_redirect_uri_callback)
|
416
|
-
@client.get_content(@srv.u('redirect1')).
|
416
|
+
expect(@client.get_content(@srv.u('redirect1'))).to eq 'hello'
|
417
417
|
@client.reset_all
|
418
418
|
@client.test_loopback_http_response << "HTTP/1.0 302 OK\nLocation: hello\n\n"
|
419
419
|
begin
|
420
420
|
@client.get_content(@srv.u('redirect1'))
|
421
|
-
false.
|
421
|
+
expect(false).to be_truthy
|
422
422
|
rescue HTTPClient::BadResponseError => e
|
423
|
-
e.res.status.
|
423
|
+
expect(e.res.status).to eq 302
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
@@ -437,7 +437,7 @@ Location: /foo
|
|
437
437
|
hello"
|
438
438
|
|
439
439
|
silent do
|
440
|
-
@client.get_content(https_url).
|
440
|
+
expect(@client.get_content(https_url)).to eq("hello")
|
441
441
|
end
|
442
442
|
end
|
443
443
|
|
@@ -450,10 +450,10 @@ hello"
|
|
450
450
|
end
|
451
451
|
|
452
452
|
it "head" do
|
453
|
-
@client.head(@srv.u("servlet")).header["x-head"][0].
|
453
|
+
expect(@client.head(@srv.u("servlet")).header["x-head"][0]).to eq("head")
|
454
454
|
param = {"1" => "2", "3" => "4"}
|
455
455
|
res = @client.head(@srv.u("servlet"), param)
|
456
|
-
params(res.header["x-query"][0]).
|
456
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
457
457
|
end
|
458
458
|
|
459
459
|
it "head async" do
|
@@ -463,32 +463,32 @@ hello"
|
|
463
463
|
Thread.pass
|
464
464
|
end
|
465
465
|
res = conn.pop
|
466
|
-
params(res.header["x-query"][0]).
|
466
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
467
467
|
end
|
468
468
|
|
469
469
|
it "get" do
|
470
|
-
@client.get(@srv.u("servlet")).content.
|
470
|
+
expect(@client.get(@srv.u("servlet")).content).to eq("get")
|
471
471
|
param = {"1" => "2", "3" => "4"}
|
472
472
|
res = @client.get(@srv.u("servlet"), param)
|
473
|
-
params(res.header["x-query"][0]).
|
474
|
-
res.contenttype.
|
473
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
474
|
+
expect(res.contenttype).to be_nil
|
475
475
|
url = @srv.u("servlet?5=6&7=8")
|
476
476
|
res = @client.get(url, param)
|
477
|
-
params(res.header["x-query"][0]).
|
478
|
-
res.contenttype.
|
477
|
+
expect(params(res.header["x-query"][0])).to eq(param.merge("5" => "6", "7" => "8"))
|
478
|
+
expect(res.contenttype).to be_nil
|
479
479
|
end
|
480
480
|
|
481
481
|
it "head follow redirect" do
|
482
482
|
expected = urify(@srv.u("hello"))
|
483
|
-
@client.head(@srv.u("hello"), :follow_redirect => true).header.request_uri.
|
484
|
-
@client.head(@srv.u("redirect1"), :follow_redirect => true).header.request_uri.
|
485
|
-
@client.head(@srv.u("redirect2"), :follow_redirect => true).header.request_uri.
|
483
|
+
expect(@client.head(@srv.u("hello"), :follow_redirect => true).header.request_uri).to eq(expected)
|
484
|
+
expect(@client.head(@srv.u("redirect1"), :follow_redirect => true).header.request_uri).to eq(expected)
|
485
|
+
expect(@client.head(@srv.u("redirect2"), :follow_redirect => true).header.request_uri).to eq(expected)
|
486
486
|
end
|
487
487
|
|
488
488
|
it "get follow redirect" do
|
489
|
-
@client.get(@srv.u("hello"), :follow_redirect => true).body.
|
490
|
-
@client.get(@srv.u("redirect1"), :follow_redirect => true).body.
|
491
|
-
@client.get(@srv.u("redirect2"), :follow_redirect => true).body.
|
489
|
+
expect(@client.get(@srv.u("hello"), :follow_redirect => true).body).to eq("hello")
|
490
|
+
expect(@client.get(@srv.u("redirect1"), :follow_redirect => true).body).to eq("hello")
|
491
|
+
expect(@client.get(@srv.u("redirect2"), :follow_redirect => true).body).to eq("hello")
|
492
492
|
end
|
493
493
|
|
494
494
|
it "get async" do
|
@@ -498,23 +498,23 @@ hello"
|
|
498
498
|
Thread.pass
|
499
499
|
end
|
500
500
|
res = conn.pop
|
501
|
-
params(res.header["x-query"][0]).
|
501
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
502
502
|
end
|
503
503
|
|
504
504
|
it "get async for largebody" do
|
505
505
|
conn = @client.get_async(@srv.u("largebody"))
|
506
506
|
res = conn.pop
|
507
|
-
res.content.read.length.
|
507
|
+
expect(res.content.read.length).to eq(1000.*(1000))
|
508
508
|
end
|
509
509
|
|
510
510
|
it "get with block" do
|
511
511
|
called = false
|
512
512
|
res = @client.get(@srv.u("servlet")) do |str|
|
513
|
-
str.
|
513
|
+
expect(str).to eq("get")
|
514
514
|
called = true
|
515
515
|
end
|
516
|
-
called.
|
517
|
-
res.content.
|
516
|
+
expect(called).to be_truthy
|
517
|
+
expect(res.content).to be_nil
|
518
518
|
end
|
519
519
|
|
520
520
|
it "get with block chunk string recycle" do
|
@@ -523,65 +523,65 @@ hello"
|
|
523
523
|
res = @client.get(@srv.u("servlet")) do |str|
|
524
524
|
body << str
|
525
525
|
end
|
526
|
-
body.size.
|
527
|
-
body.join.
|
526
|
+
expect(body.size).to eq(2)
|
527
|
+
expect(body.join).to eq("get")
|
528
528
|
end
|
529
529
|
|
530
530
|
it "post" do
|
531
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
531
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
532
532
|
param = {"1" => "2", "3" => "4"}
|
533
533
|
res = @client.post(@srv.u("servlet"), param)
|
534
|
-
params(res.header["x-query"][0]).
|
534
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
535
535
|
end
|
536
536
|
|
537
537
|
it "post follow redirect" do
|
538
|
-
@client.post(@srv.u("hello"), :follow_redirect => true).body.
|
539
|
-
@client.post(@srv.u("redirect1"), :follow_redirect => true).body.
|
540
|
-
@client.post(@srv.u("redirect2"), :follow_redirect => true).body.
|
538
|
+
expect(@client.post(@srv.u("hello"), :follow_redirect => true).body).to eq("hello")
|
539
|
+
expect(@client.post(@srv.u("redirect1"), :follow_redirect => true).body).to eq("hello")
|
540
|
+
expect(@client.post(@srv.u("redirect2"), :follow_redirect => true).body).to eq("hello")
|
541
541
|
end
|
542
542
|
|
543
543
|
it "post with content type" do
|
544
544
|
param = [["1", "2"], ["3", "4"]]
|
545
545
|
ext = {"content-type" => "application/x-www-form-urlencoded", "hello" => "world"}
|
546
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
546
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
547
547
|
res = @client.post(@srv.u("servlet"), param, ext)
|
548
|
-
params(res.header["x-query"][0]).
|
548
|
+
expect(params(res.header["x-query"][0])).to eq(Hash[param])
|
549
549
|
ext = [["content-type", "multipart/form-data"], ["hello", "world"]]
|
550
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
550
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
551
551
|
res = @client.post(@srv.u("servlet"), param, ext)
|
552
|
-
res.content.
|
553
|
-
res.content.
|
552
|
+
expect(res.content).to match /Content-Disposition: form-data; name="1"/
|
553
|
+
expect(res.content).to match /Content-Disposition: form-data; name="3"/
|
554
554
|
ext = {"content-type" => "multipart/form-data; boundary=hello"}
|
555
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
555
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
556
556
|
res = @client.post(@srv.u("servlet"), param, ext)
|
557
|
-
res.content.
|
558
|
-
res.content.
|
559
|
-
res.content.
|
557
|
+
expect(res.content).to match /Content-Disposition: form-data; name="1"/
|
558
|
+
expect(res.content).to match /Content-Disposition: form-data; name="3"/
|
559
|
+
expect(res.content).to eq("post,--hello\r\nContent-Disposition: form-data; name=\"1\"\r\n\r\n2\r\n--hello\r\nContent-Disposition: form-data; name=\"3\"\r\n\r\n4\r\n--hello--\r\n\r\n")
|
560
560
|
end
|
561
561
|
|
562
562
|
it "post with custom multipart and boolean params" do
|
563
563
|
param = [["boolean_true", true]]
|
564
564
|
ext = {"content-type" => "multipart/form-data"}
|
565
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
565
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
566
566
|
res = @client.post(@srv.u("servlet"), param, ext)
|
567
|
-
res.content.
|
567
|
+
expect(res.content).to match /Content-Disposition: form-data; name="boolean_true"\r\n\r\ntrue\r\n/
|
568
568
|
|
569
569
|
param = [["boolean_false", false]]
|
570
570
|
res = @client.post(@srv.u("servlet"), param, ext)
|
571
|
-
res.content.
|
571
|
+
expect(res.content).to match /Content-Disposition: form-data; name="boolean_false"\r\n\r\nfalse\r\n/
|
572
572
|
|
573
573
|
param = [["nil", nil]]
|
574
574
|
res = @client.post(@srv.u("servlet"), param, ext)
|
575
|
-
res.content.
|
575
|
+
expect(res.content).to match /Content-Disposition: form-data; name="nil"\r\n\r\n\r\n/
|
576
576
|
end
|
577
577
|
|
578
578
|
it "post with file" do
|
579
579
|
STDOUT.sync = true
|
580
580
|
File.open(__FILE__) do |file|
|
581
581
|
res = @client.post(@srv.u("servlet"), 1 => 2, 3 => file)
|
582
|
-
res.content.
|
583
|
-
res.content.
|
584
|
-
res.content.
|
582
|
+
expect(res.content).to match /^Content-Disposition: form-data; name="1"\r\n/mn
|
583
|
+
expect(res.content).to match /^Content-Disposition: form-data; name="3";/
|
584
|
+
expect(res.content).to match /FIND_TAG_IN_THIS_FILE/
|
585
585
|
end
|
586
586
|
end
|
587
587
|
|
@@ -609,11 +609,11 @@ hello"
|
|
609
609
|
end
|
610
610
|
@client.debug_dev = str = StringIO.new
|
611
611
|
res = @client.post(@srv.u("servlet"), 1 => 2, 3 => myio)
|
612
|
-
res.content.
|
613
|
-
res.content.
|
614
|
-
res.content.
|
615
|
-
str.string.
|
616
|
-
myio.called.
|
612
|
+
expect(res.content).to match /\r\nContent-Disposition: form-data; name="1"\r\n/m
|
613
|
+
expect(res.content).to match /\r\n2\r\n/m
|
614
|
+
expect(res.content).to match /\r\nContent-Disposition: form-data; name="3"; filename=""\r\n/m
|
615
|
+
expect(str.string).to match /\r\nContent-Length:/m
|
616
|
+
expect(myio.called).to eq(3)
|
617
617
|
end
|
618
618
|
|
619
619
|
it "post with io nosize" do
|
@@ -623,10 +623,10 @@ hello"
|
|
623
623
|
end
|
624
624
|
@client.debug_dev = str = StringIO.new
|
625
625
|
res = @client.post(@srv.u("servlet"), {1 => 2, 3 => myio})
|
626
|
-
res.content.
|
627
|
-
res.content.
|
628
|
-
res.content.
|
629
|
-
res.content.
|
626
|
+
expect(res.content).to match /\r\nContent-Disposition: form-data; name="1"\r\n/m
|
627
|
+
expect(res.content).to match /\r\n2\r\n/m
|
628
|
+
expect(res.content).to match /\r\nContent-Disposition: form-data; name="3"; filename=""\r\n/m
|
629
|
+
expect(res.content).to match /\r\n4\r\n/m
|
630
630
|
# TODO is this needed?
|
631
631
|
#res.content.should match /\r\nTransfer-Encoding: chunked\r\n/m
|
632
632
|
end
|
@@ -638,42 +638,42 @@ hello"
|
|
638
638
|
Thread.pass
|
639
639
|
end
|
640
640
|
res = conn.pop
|
641
|
-
params(res.header["x-query"][0]).
|
641
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
642
642
|
end
|
643
643
|
|
644
644
|
it "post with block" do
|
645
645
|
called = false
|
646
646
|
res = @client.post(@srv.u("servlet")) do |str|
|
647
|
-
str.
|
647
|
+
expect(str).to eq("post,")
|
648
648
|
called = true
|
649
649
|
end
|
650
|
-
called.
|
651
|
-
res.content.
|
650
|
+
expect(called).to be_truthy
|
651
|
+
expect(res.content).to be_nil
|
652
652
|
called = false
|
653
653
|
param = [["1", "2"], ["3", "4"]]
|
654
654
|
res = @client.post(@srv.u("servlet"), param) do |str|
|
655
|
-
str.
|
655
|
+
expect(str).to eq("post,1=2&3=4")
|
656
656
|
called = true
|
657
657
|
end
|
658
|
-
called.
|
659
|
-
res.header["x-query"][0].
|
660
|
-
res.content.
|
658
|
+
expect(called).to be_truthy
|
659
|
+
expect(res.header["x-query"][0]).to eq("1=2&3=4")
|
660
|
+
expect(res.content).to be_nil
|
661
661
|
end
|
662
662
|
|
663
663
|
it "post with custom multipart" do
|
664
664
|
ext = {"content-type" => "multipart/form-data"}
|
665
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
665
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
666
666
|
body = [{ 'Content-Disposition' => 'form-data; name="1"', :content => "2"},
|
667
667
|
{ 'Content-Disposition' => 'form-data; name="3"', :content => "4"}]
|
668
668
|
res = @client.post(@srv.u("servlet"), body, ext)
|
669
|
-
res.content.
|
670
|
-
res.content.
|
669
|
+
expect(res.content).to match /Content-Disposition: form-data; name="1"/
|
670
|
+
expect(res.content).to match /Content-Disposition: form-data; name="3"/
|
671
671
|
ext = {"content-type" => "multipart/form-data; boundary=hello"}
|
672
|
-
@client.post(@srv.u("servlet")).content[0, 4].
|
672
|
+
expect(@client.post(@srv.u("servlet")).content[0, 4]).to eq("post")
|
673
673
|
res = @client.post(@srv.u("servlet"), body, ext)
|
674
|
-
res.content.
|
675
|
-
res.content.
|
676
|
-
res.content.
|
674
|
+
expect(res.content).to match /Content-Disposition: form-data; name="1"/
|
675
|
+
expect(res.content).to match /Content-Disposition: form-data; name="3"/
|
676
|
+
expect(res.content).to eq("post,--hello\r\nContent-Disposition: form-data; name=\"1\"\r\n\r\n2\r\n--hello\r\nContent-Disposition: form-data; name=\"3\"\r\n\r\n4\r\n--hello--\r\n\r\n")
|
677
677
|
end
|
678
678
|
|
679
679
|
it "post with custom multipart and file" do
|
@@ -682,26 +682,26 @@ hello"
|
|
682
682
|
ext = {"Content-Type" => "multipart/alternative"}
|
683
683
|
body = [{"Content-Type" => "text/plain", :content => "this is only a test"}, {"Content-Type" => "application/x-ruby", :content => file}]
|
684
684
|
res = @client.post(@srv.u("servlet"), body, ext)
|
685
|
-
res.content.
|
686
|
-
res.content.
|
687
|
-
res.content.
|
688
|
-
res.content.
|
685
|
+
expect(res.content).to match /^Content-Type: text\/plain\r\n/m
|
686
|
+
expect(res.content).to match /^this is only a test\r\n/m
|
687
|
+
expect(res.content).to match /^Content-Type: application\/x-ruby\r\n/m
|
688
|
+
expect(res.content).to match /FIND_TAG_IN_THIS_FILE/
|
689
689
|
end
|
690
690
|
end
|
691
691
|
|
692
692
|
it "put" do
|
693
|
-
@client.put(@srv.u("servlet")).content.
|
693
|
+
expect(@client.put(@srv.u("servlet")).content).to eq("put")
|
694
694
|
param = {"1" => "2", "3" => "4"}
|
695
695
|
@client.debug_dev = str = ""
|
696
696
|
res = @client.put(@srv.u("servlet"), param)
|
697
|
-
params(res.header["x-query"][0]).
|
698
|
-
str.split(/\r?\n/)[5].
|
697
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
698
|
+
expect(str.split(/\r?\n/)[5]).to eq("Content-Type: application/x-www-form-urlencoded")
|
699
699
|
end
|
700
700
|
|
701
701
|
it "put bytesize" do
|
702
702
|
res = @client.put(@srv.u("servlet"), "txt" => "あいうえお")
|
703
|
-
res.header["x-query"][0].
|
704
|
-
res.header["x-size"][0].
|
703
|
+
expect(res.header["x-query"][0]).to eq("txt=%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A")
|
704
|
+
expect(res.header["x-size"][0]).to eq("15")
|
705
705
|
end
|
706
706
|
|
707
707
|
it "put async" do
|
@@ -711,16 +711,16 @@ hello"
|
|
711
711
|
Thread.pass
|
712
712
|
end
|
713
713
|
res = conn.pop
|
714
|
-
params(res.header["x-query"][0]).
|
714
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
715
715
|
end
|
716
716
|
|
717
717
|
it "patch" do
|
718
|
-
@client.patch(@srv.u("servlet")).content.
|
718
|
+
expect(@client.patch(@srv.u("servlet")).content).to eq("patch")
|
719
719
|
param = {"1" => "2", "3" => "4"}
|
720
720
|
@client.debug_dev = str = ""
|
721
721
|
res = @client.patch(@srv.u("servlet"), param)
|
722
|
-
params(res.header["x-query"][0]).
|
723
|
-
str.split(/\r?\n/)[5].
|
722
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
723
|
+
expect(str.split(/\r?\n/)[5]).to eq("Content-Type: application/x-www-form-urlencoded")
|
724
724
|
end
|
725
725
|
|
726
726
|
it "patch async" do
|
@@ -730,18 +730,18 @@ hello"
|
|
730
730
|
Thread.pass
|
731
731
|
end
|
732
732
|
res = conn.pop
|
733
|
-
params(res.header["x-query"][0]).
|
733
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
734
734
|
end
|
735
735
|
|
736
736
|
it "delete" do
|
737
|
-
@client.delete(@srv.u("servlet")).content.
|
737
|
+
expect(@client.delete(@srv.u("servlet")).content).to eq("delete")
|
738
738
|
end
|
739
739
|
|
740
740
|
it "delete with body" do
|
741
741
|
param = {'1'=>'2', '3'=>'4'}
|
742
742
|
@client.debug_dev = str = ''
|
743
|
-
@client.delete(@srv.u('servlet'), param).content.
|
744
|
-
HTTP::Message.parse(str.split(/\r?\n\r?\n/)[2]).
|
743
|
+
expect(@client.delete(@srv.u('servlet'), param).content).to eq "delete"
|
744
|
+
expect(HTTP::Message.parse(str.split(/\r?\n\r?\n/)[2])).to eq({'1' => ['2'], '3' => ['4']})
|
745
745
|
end
|
746
746
|
|
747
747
|
it "delete async" do
|
@@ -750,11 +750,11 @@ hello"
|
|
750
750
|
Thread.pass
|
751
751
|
end
|
752
752
|
res = conn.pop
|
753
|
-
res.content.read.
|
753
|
+
expect(res.content.read).to eq("delete")
|
754
754
|
end
|
755
755
|
|
756
756
|
it "options" do
|
757
|
-
@client.options(@srv.u("servlet")).content.
|
757
|
+
expect(@client.options(@srv.u("servlet")).content).to eq("options")
|
758
758
|
end
|
759
759
|
|
760
760
|
it "options async" do
|
@@ -763,11 +763,11 @@ hello"
|
|
763
763
|
Thread.pass
|
764
764
|
end
|
765
765
|
res = conn.pop
|
766
|
-
res.content.read.
|
766
|
+
expect(res.content.read).to eq("options")
|
767
767
|
end
|
768
768
|
|
769
769
|
it "propfind" do
|
770
|
-
@client.propfind(@srv.u("servlet")).content.
|
770
|
+
expect(@client.propfind(@srv.u("servlet")).content).to eq("propfind")
|
771
771
|
end
|
772
772
|
|
773
773
|
it "propfind async" do
|
@@ -776,15 +776,15 @@ hello"
|
|
776
776
|
Thread.pass
|
777
777
|
end
|
778
778
|
res = conn.pop
|
779
|
-
res.content.read.
|
779
|
+
expect(res.content.read).to eq("propfind")
|
780
780
|
end
|
781
781
|
|
782
782
|
it "proppatch" do
|
783
|
-
@client.proppatch(@srv.u("servlet")).content.
|
783
|
+
expect(@client.proppatch(@srv.u("servlet")).content).to eq("proppatch")
|
784
784
|
param = {"1" => "2", "3" => "4"}
|
785
785
|
res = @client.proppatch(@srv.u("servlet"), param)
|
786
|
-
res.content.
|
787
|
-
params(res.header["x-query"][0]).
|
786
|
+
expect(res.content).to eq("proppatch")
|
787
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
788
788
|
end
|
789
789
|
|
790
790
|
it "proppatch async" do
|
@@ -794,15 +794,15 @@ hello"
|
|
794
794
|
Thread.pass
|
795
795
|
end
|
796
796
|
res = conn.pop
|
797
|
-
res.content.read.
|
798
|
-
params(res.header["x-query"][0]).
|
797
|
+
expect(res.content.read).to eq("proppatch")
|
798
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
799
799
|
end
|
800
800
|
|
801
801
|
it "trace" do
|
802
|
-
@client.trace(@srv.u("servlet")).content.
|
802
|
+
expect(@client.trace(@srv.u("servlet")).content).to eq("trace")
|
803
803
|
param = {"1" => "2", "3" => "4"}
|
804
804
|
res = @client.trace(@srv.u("servlet"), param)
|
805
|
-
params(res.header["x-query"][0]).
|
805
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
806
806
|
end
|
807
807
|
|
808
808
|
it "trace async" do
|
@@ -812,55 +812,55 @@ hello"
|
|
812
812
|
Thread.pass
|
813
813
|
end
|
814
814
|
res = conn.pop
|
815
|
-
params(res.header["x-query"][0]).
|
815
|
+
expect(params(res.header["x-query"][0])).to eq(param)
|
816
816
|
end
|
817
817
|
|
818
818
|
it "chunked" do
|
819
|
-
@client.get_content(@srv.u("chunked"), "msg" => "chunked").
|
820
|
-
@client.get_content(@srv.u("chunked"), "msg" => "あいうえお").
|
819
|
+
expect(@client.get_content(@srv.u("chunked"), "msg" => "chunked")).to eq("chunked")
|
820
|
+
expect(@client.get_content(@srv.u("chunked"), "msg" => "あいうえお")).to eq("あいうえお")
|
821
821
|
end
|
822
822
|
|
823
823
|
it "chunked empty" do
|
824
|
-
@client.get_content(@srv.u("chunked"), "msg" => "").
|
824
|
+
expect(@client.get_content(@srv.u("chunked"), "msg" => "")).to eq("")
|
825
825
|
end
|
826
826
|
|
827
827
|
it "get query" do
|
828
|
-
check_query_get({1=>2}).
|
829
|
-
check_query_get({"a"=>"A", "B"=>"b"}).
|
830
|
-
check_query_get({"&"=>"&"}).
|
831
|
-
check_query_get({"= "=>" =+"}).
|
832
|
-
['=', '&'].sort.
|
828
|
+
expect(check_query_get({1=>2})).to eq({'1'=>'2'})
|
829
|
+
expect(check_query_get({"a"=>"A", "B"=>"b"})).to eq({'a'=>'A', 'B'=>'b'})
|
830
|
+
expect(check_query_get({"&"=>"&"})).to eq({'&'=>'&'})
|
831
|
+
expect(check_query_get({"= "=>" =+"})).to eq({'= '=>' =+'})
|
832
|
+
expect(['=', '&'].sort).to eq check_query_get([["=", "="], ["=", "&"]])['='].to_ary.sort
|
833
833
|
|
834
|
-
{'123'=>'45'}.
|
835
|
-
{'12 3'=>'45', ' '=>' '}.
|
836
|
-
{}.
|
837
|
-
{'1'=>'2'}.
|
838
|
-
{'1'=>'2', '3'=>'4'}.
|
834
|
+
expect({'123'=>'45'}).to eq check_query_get('123=45')
|
835
|
+
expect({'12 3'=>'45', ' '=>' '}).to eq check_query_get('12+3=45&+=+')
|
836
|
+
expect({}).to eq check_query_get('')
|
837
|
+
expect({'1'=>'2'}).to eq check_query_get({1=>StringIO.new('2')})
|
838
|
+
expect({'1'=>'2', '3'=>'4'}).to eq check_query_get(StringIO.new('3=4&1=2'))
|
839
839
|
|
840
840
|
hash = check_query_get({"a"=>["A","a"], "B"=>"b"})
|
841
|
-
{'a'=>'A', 'B'=>'b'}.
|
842
|
-
['A','a'].
|
841
|
+
expect({'a'=>'A', 'B'=>'b'}).to eq hash
|
842
|
+
expect(['A','a']).to eq hash['a'].to_ary
|
843
843
|
|
844
844
|
hash = check_query_get({"a"=>WEBrick::HTTPUtils::FormData.new("A","a"), "B"=>"b"})
|
845
|
-
{'a'=>'A', 'B'=>'b'}.
|
846
|
-
['A','a'].
|
845
|
+
expect({'a'=>'A', 'B'=>'b'}).to eq hash
|
846
|
+
expect(['A','a']).to eq hash['a'].to_ary
|
847
847
|
|
848
848
|
hash = check_query_get({"a"=>[StringIO.new("A"),StringIO.new("a")], "B"=>StringIO.new("b")})
|
849
|
-
{'a'=>'A', 'B'=>'b'}.
|
850
|
-
['A','a'].
|
849
|
+
expect({'a'=>'A', 'B'=>'b'}).to eq hash
|
850
|
+
expect(['A','a']).to eq hash['a'].to_ary
|
851
851
|
end
|
852
852
|
|
853
853
|
it "post body" do
|
854
|
-
check_query_post(1 => 2).
|
855
|
-
check_query_post("a" => "A", "B" => "b").
|
856
|
-
check_query_post("&" => "&").
|
857
|
-
check_query_post("= " => " =+").
|
858
|
-
check_query_post([["=", "="], ["=", "&"]])["="].to_ary.sort.
|
859
|
-
check_query_post("123=45").
|
860
|
-
check_query_post("12+3=45&+=+").
|
861
|
-
check_query_post("").
|
854
|
+
expect(check_query_post(1 => 2)).to eq({"1" => "2"})
|
855
|
+
expect(check_query_post("a" => "A", "B" => "b")).to eq({"a" => "A", "B" => "b"})
|
856
|
+
expect(check_query_post("&" => "&")).to eq({"&" => "&"})
|
857
|
+
expect(check_query_post("= " => " =+")).to eq({"= " => " =+"})
|
858
|
+
expect(check_query_post([["=", "="], ["=", "&"]])["="].to_ary.sort).to eq(["=", "&"].sort)
|
859
|
+
expect(check_query_post("123=45")).to eq({"123" => "45"})
|
860
|
+
expect(check_query_post("12+3=45&+=+")).to eq({"12 3" => "45", " " => " "})
|
861
|
+
expect(check_query_post("")).to eq({})
|
862
862
|
post_body = StringIO.new("foo=bar&foo=baz")
|
863
|
-
check_query_post(post_body)["foo"].to_ary.sort.
|
863
|
+
expect(check_query_post(post_body)["foo"].to_ary.sort).to eq(["bar", "baz"])
|
864
864
|
end
|
865
865
|
|
866
866
|
it "extra headers" do
|
@@ -868,34 +868,34 @@ hello"
|
|
868
868
|
@client.debug_dev = str
|
869
869
|
@client.head(@srv.u, nil, "ABC" => "DEF")
|
870
870
|
lines = str.split(/(?:\r?\n)+/)
|
871
|
-
lines[0].
|
872
|
-
lines[4].
|
871
|
+
expect(lines[0]).to eq("= Request")
|
872
|
+
expect(lines[4]).to match "ABC: DEF"
|
873
873
|
str = ""
|
874
874
|
@client.debug_dev = str
|
875
875
|
@client.get(@srv.u, nil, [["ABC", "DEF"], ["ABC", "DEF"]])
|
876
876
|
lines = str.split(/(?:\r?\n)+/)
|
877
|
-
lines[0].
|
878
|
-
lines[4].
|
879
|
-
lines[5].
|
877
|
+
expect(lines[0]).to eq("= Request")
|
878
|
+
expect(lines[4]).to match "ABC: DEF"
|
879
|
+
expect(lines[5]).to match "ABC: DEF"
|
880
880
|
end
|
881
881
|
|
882
882
|
it "http custom date header" do
|
883
883
|
@client.debug_dev = str = ""
|
884
884
|
res = @client.get(@srv.u("hello"), :header => {"Date" => "foo"})
|
885
885
|
lines = str.split(/(?:\r?\n)+/)
|
886
|
-
lines[4].
|
886
|
+
expect(lines[4]).to eq("Date: foo")
|
887
887
|
end
|
888
888
|
|
889
889
|
it "timeout" do
|
890
|
-
@client.connect_timeout.
|
891
|
-
@client.send_timeout.
|
892
|
-
@client.receive_timeout.
|
890
|
+
expect(@client.connect_timeout).to eq(60)
|
891
|
+
expect(@client.send_timeout).to eq(120)
|
892
|
+
expect(@client.receive_timeout).to eq(60)
|
893
893
|
@client.connect_timeout = 1
|
894
894
|
@client.send_timeout = 2
|
895
895
|
@client.receive_timeout = 3
|
896
|
-
@client.connect_timeout.
|
897
|
-
@client.send_timeout.
|
898
|
-
@client.receive_timeout.
|
896
|
+
expect(@client.connect_timeout).to eq(1)
|
897
|
+
expect(@client.send_timeout).to eq(2)
|
898
|
+
expect(@client.receive_timeout).to eq(3)
|
899
899
|
end
|
900
900
|
|
901
901
|
it "connect timeout" do
|
@@ -907,28 +907,28 @@ hello"
|
|
907
907
|
end
|
908
908
|
|
909
909
|
it "receive timeout" do
|
910
|
-
@client.get_content(@srv.u("sleep?sec=2")).
|
910
|
+
expect(@client.get_content(@srv.u("sleep?sec=2"))).to eq("hello")
|
911
911
|
@client.receive_timeout = 1
|
912
|
-
@client.get_content(@srv.u("sleep?sec=0")).
|
912
|
+
expect(@client.get_content(@srv.u("sleep?sec=0"))).to eq("hello")
|
913
913
|
|
914
914
|
expect {
|
915
915
|
@client.get_content(@srv.u("sleep?sec=2"))
|
916
916
|
}.to raise_error(HTTPClient::ReceiveTimeoutError)
|
917
917
|
@client.receive_timeout = 3
|
918
|
-
@client.get_content(@srv.u("sleep?sec=2")).
|
918
|
+
expect(@client.get_content(@srv.u("sleep?sec=2"))).to eq("hello")
|
919
919
|
end
|
920
920
|
|
921
921
|
it "receive timeout post" do
|
922
|
-
@client.post(@srv.u("sleep"), :sec => 2).content.
|
922
|
+
expect(@client.post(@srv.u("sleep"), :sec => 2).content).to eq("hello")
|
923
923
|
@client.receive_timeout = 1
|
924
|
-
@client.post(@srv.u("sleep"), :sec => 0).content.
|
924
|
+
expect(@client.post(@srv.u("sleep"), :sec => 0).content).to eq("hello")
|
925
925
|
|
926
926
|
expect {
|
927
927
|
@client.post(@srv.u("sleep"), :sec => 2)\
|
928
928
|
}.to raise_error(HTTPClient::ReceiveTimeoutError)
|
929
929
|
|
930
930
|
@client.receive_timeout = 3
|
931
|
-
@client.post(@srv.u("sleep"), :sec => 2).content.
|
931
|
+
expect(@client.post(@srv.u("sleep"), :sec => 2).content).to eq("hello")
|
932
932
|
end
|
933
933
|
|
934
934
|
it "reset" do
|
@@ -956,7 +956,7 @@ hello"
|
|
956
956
|
@client.set_cookie_store(cookiefile)
|
957
957
|
cookie = @client.cookie_manager.cookies.first
|
958
958
|
url = cookie.url
|
959
|
-
cookie.domain_match(url.host, cookie.domain).
|
959
|
+
expect(cookie.domain_match(url.host, cookie.domain)).to be_truthy
|
960
960
|
@client.reset_all
|
961
961
|
@client.test_loopback_http_response << "HTTP/1.0 200 OK
|
962
962
|
Set-Cookie: foo=bar; expires=#{Time.at(1924873200).gmtime.httpdate}
|
@@ -965,7 +965,7 @@ OK"
|
|
965
965
|
@client.get_content("http://rubyforge.org/account/login.php")
|
966
966
|
@client.save_cookie_store
|
967
967
|
str = File.read(cookiefile)
|
968
|
-
str.
|
968
|
+
expect(str).to match /http:\/\/rubyforge.org\/account\/login.php\tfoo\tbar\t1924873200\trubyforge.org\t\/account\t1/
|
969
969
|
File.unlink(cookiefile)
|
970
970
|
end
|
971
971
|
|
@@ -1023,68 +1023,68 @@ OK"
|
|
1023
1023
|
|
1024
1024
|
it "connection" do
|
1025
1025
|
c = HTTPClient::Connection.new
|
1026
|
-
c.finished
|
1027
|
-
c.join.
|
1026
|
+
expect(c.finished?).to be_truthy
|
1027
|
+
expect(c.join).to be_nil
|
1028
1028
|
end
|
1029
1029
|
|
1030
1030
|
it "site" do
|
1031
1031
|
site = HTTPClient::Site.new
|
1032
|
-
site.scheme.
|
1033
|
-
site.host.
|
1034
|
-
site.port.
|
1035
|
-
site.addr.
|
1036
|
-
site.to_s.
|
1032
|
+
expect(site.scheme).to eq("tcp")
|
1033
|
+
expect(site.host).to eq("0.0.0.0")
|
1034
|
+
expect(site.port).to eq(0)
|
1035
|
+
expect(site.addr).to eq("tcp://0.0.0.0:0")
|
1036
|
+
expect(site.to_s).to eq("tcp://0.0.0.0:0")
|
1037
1037
|
|
1038
1038
|
site.inspect
|
1039
1039
|
site = HTTPClient::Site.new(urify("http://localhost:12345/foo"))
|
1040
|
-
site.scheme.
|
1041
|
-
site.host.
|
1042
|
-
site.port.
|
1043
|
-
site.addr.
|
1044
|
-
site.to_s.
|
1040
|
+
expect(site.scheme).to eq("http")
|
1041
|
+
expect(site.host).to eq("localhost")
|
1042
|
+
expect(site.port).to eq(12345)
|
1043
|
+
expect(site.addr).to eq("http://localhost:12345")
|
1044
|
+
expect(site.to_s).to eq("http://localhost:12345")
|
1045
1045
|
|
1046
1046
|
site.inspect
|
1047
1047
|
site1 = HTTPClient::Site.new(urify("http://localhost:12341/"))
|
1048
1048
|
site2 = HTTPClient::Site.new(urify("http://localhost:12342/"))
|
1049
1049
|
site3 = HTTPClient::Site.new(urify("http://localhost:12342/"))
|
1050
|
-
site1.
|
1050
|
+
expect(site1).not_to eq(site2)
|
1051
1051
|
h = {site1 => "site1", site2 => "site2"}
|
1052
1052
|
h[site3] = "site3"
|
1053
|
-
h[site1].
|
1054
|
-
h[site2].
|
1053
|
+
expect(h[site1]).to eq("site1")
|
1054
|
+
expect(h[site2]).to eq("site3")
|
1055
1055
|
end
|
1056
1056
|
|
1057
1057
|
it "http header" do
|
1058
1058
|
res = @client.get(@srv.u("hello"))
|
1059
|
-
res.contenttype.
|
1060
|
-
res.header.get(nil).size.
|
1059
|
+
expect(res.contenttype).to eq("text/html")
|
1060
|
+
expect(res.header.get(nil).size).to eq(5)
|
1061
1061
|
res.header.delete("connection")
|
1062
|
-
res.header.get(nil).size.
|
1062
|
+
expect(res.header.get(nil).size).to eq(4)
|
1063
1063
|
res.header["foo"] = "bar"
|
1064
|
-
res.header["foo"].
|
1065
|
-
res.header.get("foo").
|
1064
|
+
expect(res.header["foo"]).to eq(["bar"])
|
1065
|
+
expect(res.header.get("foo")).to eq([["foo", "bar"]])
|
1066
1066
|
res.header["foo"] = ["bar", "bar2"]
|
1067
|
-
res.header.get("foo").
|
1067
|
+
expect(res.header.get("foo")).to eq([["foo", "bar"], ["foo", "bar2"]])
|
1068
1068
|
end
|
1069
1069
|
|
1070
1070
|
it "session manager" do
|
1071
1071
|
mgr = HTTPClient::SessionManager.new(@client)
|
1072
|
-
(mgr.instance_eval do
|
1072
|
+
expect(mgr.instance_eval do
|
1073
1073
|
@proxy
|
1074
|
-
end).
|
1075
|
-
mgr.debug_dev.
|
1074
|
+
end).to be_nil
|
1075
|
+
expect(mgr.debug_dev).to be_nil
|
1076
1076
|
@client.debug_dev = Object.new
|
1077
1077
|
@client.proxy = "http://myproxy:12345"
|
1078
1078
|
mgr = HTTPClient::SessionManager.new(@client)
|
1079
|
-
mgr.instance_eval do
|
1079
|
+
expect(mgr.instance_eval do
|
1080
1080
|
@proxy
|
1081
|
-
end.to_s.
|
1082
|
-
mgr.debug_dev.
|
1081
|
+
end.to_s).to eq("http://myproxy:12345")
|
1082
|
+
expect(mgr.debug_dev).to eq(@client.debug_dev)
|
1083
1083
|
end
|
1084
1084
|
|
1085
1085
|
it "socket local" do
|
1086
1086
|
@client.socket_local.host = '127.0.0.1'
|
1087
|
-
@client.get_content(@srv.u('hello')).
|
1087
|
+
expect(@client.get_content(@srv.u('hello'))).to eq('hello')
|
1088
1088
|
@client.reset_all
|
1089
1089
|
@client.socket_local.port = @srv.port
|
1090
1090
|
begin
|
@@ -1097,23 +1097,27 @@ OK"
|
|
1097
1097
|
ary = ("b".."d").map do |k|
|
1098
1098
|
["key2", k]
|
1099
1099
|
end << ["key1", "a"] << ["key3", "z"]
|
1100
|
-
HTTP::Message.escape_query(ary).
|
1100
|
+
expect(HTTP::Message.escape_query(ary)).to eq("key2=b&key2=c&key2=d&key1=a&key3=z")
|
1101
1101
|
end
|
1102
1102
|
it 'charset' do
|
1103
1103
|
body = @client.get(@srv.u("charset")).body
|
1104
|
-
body.encoding.
|
1105
|
-
body.
|
1104
|
+
expect(body.encoding).to eq(Encoding::EUC_JP)
|
1105
|
+
expect(body).to eq("あいうえお".encode(Encoding::EUC_JP))
|
1106
1106
|
end
|
1107
1107
|
it 'continue' do
|
1108
1108
|
@client.debug_dev = str = ''
|
1109
1109
|
res = @client.get(@srv.u('continue'), :header => {:Expect => '100-continue'})
|
1110
|
-
res.status.
|
1111
|
-
res.body.
|
1112
|
-
str.
|
1110
|
+
expect(res.status).to eq 200
|
1111
|
+
expect(res.body).to eq 'done!'
|
1112
|
+
expect(str).to match /Expect: 100-continue/
|
1113
1113
|
end
|
1114
1114
|
|
1115
1115
|
it 'ipv6' do
|
1116
|
-
|
1116
|
+
begin
|
1117
|
+
server = TCPServer.open('::1', 0)
|
1118
|
+
rescue
|
1119
|
+
next # Skip if IPv6 is unavailable.
|
1120
|
+
end
|
1117
1121
|
server_thread = Thread.new {
|
1118
1122
|
Thread.abort_on_exception = true
|
1119
1123
|
sock = server.accept
|
@@ -1128,7 +1132,7 @@ OK"
|
|
1128
1132
|
}
|
1129
1133
|
uri = "http://[::1]:#{server.addr[1]}/"
|
1130
1134
|
begin
|
1131
|
-
@client.get(uri).body.
|
1135
|
+
expect(@client.get(uri).body).to eq '12345'
|
1132
1136
|
ensure
|
1133
1137
|
server.close
|
1134
1138
|
server_thread.kill
|