http.rb 0.18.2 → 0.19.0
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 +4 -4
- data/CHANGELOG +21 -0
- data/README.md +4 -0
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/request.rb +8 -2
- data/spec/HTTP/delete_spec.rb +25 -4
- data/spec/HTTP/get_spec.rb +31 -5
- data/spec/HTTP/post_spec.rb +66 -4
- data/spec/HTTP/put_spec.rb +25 -4
- data/spec/spec_helper.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 114eef76572ba0ee1ef7efbb61fe704870a80c9bdc7d45cd5fca467de12658f6
|
|
4
|
+
data.tar.gz: bc249e876babf5aa7a4369272675e6194fc25f1816d474ef8080ad107fa1c60c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 516e828dced10204ba4b850904d7c195c027166b1dc0dcd575e09403ef5b26da936b925ab7fdfd4c0fb3c7a3e3cf8c44585a562ac647ffbf4451804b35aa9b9a
|
|
7
|
+
data.tar.gz: f3c7dc2350bd17d98abdfe9c2deb98b0923def00ea790fffbc8919280399cb5c3d5e65eaed530abb86850a54e2e790591a1c1e9f6a91a03ff2c90611c08d2760
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
# 20260522
|
|
4
|
+
# 0.19.0: Change default verify_mode to VERIFY_PEER.
|
|
5
|
+
1. ~ HTTP.request: Default verify_mode changed from OpenSSL::SSL::VERIFY_NONE to OpenSSL::SSL::VERIFY_PEER. Callers needing the old behaviour can pass verify_mode: OpenSSL::SSL::VERIFY_NONE explicitly through the options hash.
|
|
6
|
+
2. ~ spec/HTTP/get_spec.rb: + specs for default verify_mode and explicit VERIFY_NONE override; /verify_mode: 0/verify_mode: OpenSSL::SSL::VERIFY_PEER/ in redirect specs.
|
|
7
|
+
3. ~ spec/HTTP/post_spec.rb: /verify_mode: 0/verify_mode: OpenSSL::SSL::VERIFY_PEER/ in redirect specs.
|
|
8
|
+
4. ~ spec/HTTP/put_spec.rb: /verify_mode: 0/verify_mode: OpenSSL::SSL::VERIFY_PEER/ in redirect specs.
|
|
9
|
+
5. ~ spec/HTTP/delete_spec.rb: /verify_mode: 0/verify_mode: OpenSSL::SSL::VERIFY_PEER/ in redirect specs.
|
|
10
|
+
6. ~ README.md: Note the new verify_mode default and how to opt back into VERIFY_NONE.
|
|
11
|
+
7. ~ HTTP::VERSION: /0.18.3/0.19.0/
|
|
12
|
+
8. ~ CHANGELOG: + 0.19.0 entry
|
|
13
|
+
|
|
14
|
+
# 20260521
|
|
15
|
+
# 0.18.3: Fix verb preservation on 307/308 redirects.
|
|
16
|
+
1. ~ HTTP.request: Use original verb when following 307 or 308 redirects, per RFC 7231 §6.4.7 and RFC 7538. 301/302/303 keep legacy GET-on-redirect behaviour.
|
|
17
|
+
2. ~ spec/HTTP/post_spec.rb: + specs for 307/308 verb preservation and 307 body preservation.
|
|
18
|
+
3. ~ spec/HTTP/put_spec.rb: + spec for 307 verb preservation.
|
|
19
|
+
4. ~ spec/HTTP/delete_spec.rb: + spec for 307 verb preservation.
|
|
20
|
+
5. ~ spec/spec_helper.rb: Skip webmock's http_rb adapter, which collides with this gem's HTTP module on case-insensitive filesystems.
|
|
21
|
+
6. ~ HTTP::VERSION: /0.18.2/0.18.3/
|
|
22
|
+
7. ~ CHANGELOG: + 0.18.3 entry
|
|
23
|
+
|
|
3
24
|
# 20260520
|
|
4
25
|
# 0.18.2: Fix relative redirect URL construction.
|
|
5
26
|
1. ~ HTTP.request: Use URI#merge for redirect URL construction. Preserves original scheme, elides default ports, and resolves relative paths per RFC 3986.
|
data/README.md
CHANGED
|
@@ -241,6 +241,10 @@ verify_mode
|
|
|
241
241
|
# SSL/TLS session.
|
|
242
242
|
#
|
|
243
243
|
# OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER are acceptable.
|
|
244
|
+
#
|
|
245
|
+
# Defaults to OpenSSL::SSL::VERIFY_PEER as of 0.19.0. To opt back into the
|
|
246
|
+
# previous behaviour, pass verify_mode: OpenSSL::SSL::VERIFY_NONE through
|
|
247
|
+
# the options hash.
|
|
244
248
|
```
|
|
245
249
|
|
|
246
250
|
## Contributing
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/request.rb
CHANGED
|
@@ -16,7 +16,7 @@ module HTTP
|
|
|
16
16
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
17
17
|
no_redirect = options.delete(:no_redirect)
|
|
18
18
|
options[:use_ssl] ||= uri.use_ssl?
|
|
19
|
-
options[:verify_mode] ||= OpenSSL::SSL::
|
|
19
|
+
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_PEER
|
|
20
20
|
http.options = options
|
|
21
21
|
request_object.headers = headers
|
|
22
22
|
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
@@ -28,7 +28,13 @@ module HTTP
|
|
|
28
28
|
return response
|
|
29
29
|
end
|
|
30
30
|
redirect_uri = uri.merge(response.header['location'])
|
|
31
|
-
response
|
|
31
|
+
if response.code =~ /^30[78]$/
|
|
32
|
+
verb = request_object.method.downcase.to_sym
|
|
33
|
+
data = VERBS::WITH_BODY.include?(verb) ? request_object.body : {}
|
|
34
|
+
response = send(verb, redirect_uri.to_s, data, headers, options, &block)
|
|
35
|
+
else
|
|
36
|
+
response = get(redirect_uri.to_s, {}, {}, options, &block)
|
|
37
|
+
end
|
|
32
38
|
end
|
|
33
39
|
if block_given?
|
|
34
40
|
yield response
|
data/spec/HTTP/delete_spec.rb
CHANGED
|
@@ -148,7 +148,7 @@ describe ".delete" do
|
|
|
148
148
|
|
|
149
149
|
it "does a redirect" do
|
|
150
150
|
expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
|
|
151
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
151
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
152
152
|
response = HTTP.delete(request_uri)
|
|
153
153
|
expect(response.success?).to eq(true)
|
|
154
154
|
end
|
|
@@ -163,7 +163,7 @@ describe ".delete" do
|
|
|
163
163
|
|
|
164
164
|
it "does a redirect" do
|
|
165
165
|
expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
|
|
166
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
166
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
167
167
|
response = HTTP.delete(request_uri)
|
|
168
168
|
expect(response.success?).to eq(true)
|
|
169
169
|
end
|
|
@@ -190,7 +190,7 @@ describe ".delete" do
|
|
|
190
190
|
|
|
191
191
|
it "does a redirect" do
|
|
192
192
|
expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
|
|
193
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
193
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
194
194
|
response = HTTP.delete(request_uri)
|
|
195
195
|
expect(response.success?).to eq(true)
|
|
196
196
|
end
|
|
@@ -205,13 +205,34 @@ describe ".delete" do
|
|
|
205
205
|
|
|
206
206
|
it "does a redirect" do
|
|
207
207
|
expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
|
|
208
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
208
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
209
209
|
response = HTTP.delete(request_uri)
|
|
210
210
|
expect(response.success?).to eq(true)
|
|
211
211
|
end
|
|
212
212
|
end
|
|
213
213
|
end
|
|
214
214
|
|
|
215
|
+
context "with verb-preserving redirection via 307" do
|
|
216
|
+
let(:request_uri){'http://example.com/path'}
|
|
217
|
+
let(:redirect_uri){'http://redirected.com'}
|
|
218
|
+
|
|
219
|
+
before do
|
|
220
|
+
stub_request(:delete, request_uri).
|
|
221
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
222
|
+
to_return(status: 307, body: '', headers: {'location' => redirect_uri})
|
|
223
|
+
stub_request(:delete, redirect_uri).
|
|
224
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
225
|
+
to_return(status: 200, body: '', headers: {})
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "preserves the verb" do
|
|
229
|
+
expect(HTTP).to receive(:delete).with(request_uri).and_call_original.ordered
|
|
230
|
+
expect(HTTP).to receive(:delete).with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original.ordered
|
|
231
|
+
response = HTTP.delete(request_uri)
|
|
232
|
+
expect(response.success?).to eq(true)
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
215
236
|
context "no_redirect true" do
|
|
216
237
|
let(:request_uri){'http://example.com/path'}
|
|
217
238
|
let(:redirect_uri){'http://redirected.com'}
|
data/spec/HTTP/get_spec.rb
CHANGED
|
@@ -115,6 +115,32 @@ describe ".get" do
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
+
context "with default verify_mode" do
|
|
119
|
+
let(:uri){'http://example.com/path'}
|
|
120
|
+
let(:parsed_uri){URI.parse(uri)}
|
|
121
|
+
let(:net_http_object){Net::HTTP.new(parsed_uri.host, parsed_uri.port)}
|
|
122
|
+
|
|
123
|
+
before do
|
|
124
|
+
stub_request(:get, uri).
|
|
125
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
126
|
+
to_return(status: 200, body: '', headers: {})
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "defaults verify_mode to OpenSSL::SSL::VERIFY_PEER" do
|
|
130
|
+
allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
|
|
131
|
+
response = HTTP.get(uri)
|
|
132
|
+
expect(net_http_object.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
|
|
133
|
+
expect(response.success?).to eq(true)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "allows opting back into VERIFY_NONE via options" do
|
|
137
|
+
allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
|
|
138
|
+
response = HTTP.get(uri, {}, {}, {verify_mode: OpenSSL::SSL::VERIFY_NONE})
|
|
139
|
+
expect(net_http_object.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
|
|
140
|
+
expect(response.success?).to eq(true)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
118
144
|
context "with block supplied" do
|
|
119
145
|
let(:uri){'http://example.com/path'}
|
|
120
146
|
|
|
@@ -148,7 +174,7 @@ describe ".get" do
|
|
|
148
174
|
|
|
149
175
|
it "does a redirect" do
|
|
150
176
|
expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
|
|
151
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
177
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
152
178
|
response = HTTP.get(request_uri)
|
|
153
179
|
expect(response.success?).to eq(true)
|
|
154
180
|
end
|
|
@@ -163,7 +189,7 @@ describe ".get" do
|
|
|
163
189
|
|
|
164
190
|
it "does a redirect" do
|
|
165
191
|
expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
|
|
166
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
192
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
167
193
|
response = HTTP.get(request_uri)
|
|
168
194
|
expect(response.success?).to eq(true)
|
|
169
195
|
end
|
|
@@ -190,7 +216,7 @@ describe ".get" do
|
|
|
190
216
|
|
|
191
217
|
it "does a redirect" do
|
|
192
218
|
expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
|
|
193
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
219
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
194
220
|
response = HTTP.get(request_uri)
|
|
195
221
|
expect(response.success?).to eq(true)
|
|
196
222
|
end
|
|
@@ -205,7 +231,7 @@ describe ".get" do
|
|
|
205
231
|
|
|
206
232
|
it "does a redirect" do
|
|
207
233
|
expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
|
|
208
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
234
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
209
235
|
response = HTTP.get(request_uri)
|
|
210
236
|
expect(response.success?).to eq(true)
|
|
211
237
|
end
|
|
@@ -228,7 +254,7 @@ describe ".get" do
|
|
|
228
254
|
|
|
229
255
|
it "preserves the HTTPS scheme on a relative redirect" do
|
|
230
256
|
expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
|
|
231
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: true, verify_mode:
|
|
257
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
232
258
|
response = HTTP.get(request_uri)
|
|
233
259
|
expect(response.success?).to eq(true)
|
|
234
260
|
end
|
data/spec/HTTP/post_spec.rb
CHANGED
|
@@ -286,7 +286,7 @@ describe ".post" do
|
|
|
286
286
|
|
|
287
287
|
it "does a redirect" do
|
|
288
288
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
|
289
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
289
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
290
290
|
response = HTTP.post(request_uri)
|
|
291
291
|
expect(response.success?).to eq(true)
|
|
292
292
|
end
|
|
@@ -301,7 +301,7 @@ describe ".post" do
|
|
|
301
301
|
|
|
302
302
|
it "does a redirect" do
|
|
303
303
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
|
304
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
304
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
305
305
|
response = HTTP.post(request_uri)
|
|
306
306
|
expect(response.success?).to eq(true)
|
|
307
307
|
end
|
|
@@ -328,7 +328,7 @@ describe ".post" do
|
|
|
328
328
|
|
|
329
329
|
it "does a redirect" do
|
|
330
330
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
|
331
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
331
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
332
332
|
response = HTTP.post(request_uri)
|
|
333
333
|
expect(response.success?).to eq(true)
|
|
334
334
|
end
|
|
@@ -343,13 +343,75 @@ describe ".post" do
|
|
|
343
343
|
|
|
344
344
|
it "does a redirect" do
|
|
345
345
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
|
346
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
346
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
347
347
|
response = HTTP.post(request_uri)
|
|
348
348
|
expect(response.success?).to eq(true)
|
|
349
349
|
end
|
|
350
350
|
end
|
|
351
351
|
end
|
|
352
352
|
|
|
353
|
+
context "with verb-preserving redirection" do
|
|
354
|
+
let(:request_uri){'http://example.com/path'}
|
|
355
|
+
let(:redirect_uri){'http://redirected.com'}
|
|
356
|
+
|
|
357
|
+
before do
|
|
358
|
+
stub_request(:post, redirect_uri).
|
|
359
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
360
|
+
to_return(status: 200, body: '', headers: {})
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
context "via 307" do
|
|
364
|
+
before do
|
|
365
|
+
stub_request(:post, request_uri).
|
|
366
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
367
|
+
to_return(status: 307, body: '', headers: {'location' => redirect_uri})
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
it "preserves the verb" do
|
|
371
|
+
expect(HTTP).to receive(:post).with(request_uri).and_call_original.ordered
|
|
372
|
+
expect(HTTP).to receive(:post).with(redirect_uri, '', {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original.ordered
|
|
373
|
+
response = HTTP.post(request_uri)
|
|
374
|
+
expect(response.success?).to eq(true)
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
context "via 308" do
|
|
379
|
+
before do
|
|
380
|
+
stub_request(:post, request_uri).
|
|
381
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
382
|
+
to_return(status: 308, body: '', headers: {'location' => redirect_uri})
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it "preserves the verb" do
|
|
386
|
+
expect(HTTP).to receive(:post).with(request_uri).and_call_original.ordered
|
|
387
|
+
expect(HTTP).to receive(:post).with(redirect_uri, '', {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original.ordered
|
|
388
|
+
response = HTTP.post(request_uri)
|
|
389
|
+
expect(response.success?).to eq(true)
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
context "with body-preserving redirection via 307" do
|
|
395
|
+
let(:request_uri){'http://example.com/path'}
|
|
396
|
+
let(:redirect_uri){'http://redirected.com'}
|
|
397
|
+
let(:args) do; {a: 1, b: 2}; end
|
|
398
|
+
let(:encoded_form_data){args.x_www_form_urlencode}
|
|
399
|
+
|
|
400
|
+
before do
|
|
401
|
+
stub_request(:post, request_uri).
|
|
402
|
+
with(body: encoded_form_data).
|
|
403
|
+
to_return(status: 307, body: '', headers: {'location' => redirect_uri})
|
|
404
|
+
stub_request(:post, redirect_uri).
|
|
405
|
+
with(body: encoded_form_data).
|
|
406
|
+
to_return(status: 200, body: '', headers: {})
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
it "preserves the body" do
|
|
410
|
+
response = HTTP.post(request_uri, args)
|
|
411
|
+
expect(response.success?).to eq(true)
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
|
|
353
415
|
context "no_redirect true" do
|
|
354
416
|
let(:request_uri){'http://example.com/path'}
|
|
355
417
|
let(:redirect_uri){'http://redirected.com'}
|
data/spec/HTTP/put_spec.rb
CHANGED
|
@@ -286,7 +286,7 @@ describe ".put" do
|
|
|
286
286
|
|
|
287
287
|
it "does a redirect" do
|
|
288
288
|
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
|
289
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
289
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
290
290
|
response = HTTP.put(request_uri)
|
|
291
291
|
expect(response.success?).to eq(true)
|
|
292
292
|
end
|
|
@@ -301,7 +301,7 @@ describe ".put" do
|
|
|
301
301
|
|
|
302
302
|
it "does a redirect" do
|
|
303
303
|
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
|
304
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
304
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
305
305
|
response = HTTP.put(request_uri)
|
|
306
306
|
expect(response.success?).to eq(true)
|
|
307
307
|
end
|
|
@@ -328,7 +328,7 @@ describe ".put" do
|
|
|
328
328
|
|
|
329
329
|
it "does a redirect" do
|
|
330
330
|
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
|
331
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
331
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
332
332
|
response = HTTP.put(request_uri)
|
|
333
333
|
expect(response.success?).to eq(true)
|
|
334
334
|
end
|
|
@@ -343,13 +343,34 @@ describe ".put" do
|
|
|
343
343
|
|
|
344
344
|
it "does a redirect" do
|
|
345
345
|
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
|
346
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode:
|
|
346
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
|
|
347
347
|
response = HTTP.put(request_uri)
|
|
348
348
|
expect(response.success?).to eq(true)
|
|
349
349
|
end
|
|
350
350
|
end
|
|
351
351
|
end
|
|
352
352
|
|
|
353
|
+
context "with verb-preserving redirection via 307" do
|
|
354
|
+
let(:request_uri){'http://example.com/path'}
|
|
355
|
+
let(:redirect_uri){'http://redirected.com'}
|
|
356
|
+
|
|
357
|
+
before do
|
|
358
|
+
stub_request(:put, request_uri).
|
|
359
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
360
|
+
to_return(status: 307, body: '', headers: {'location' => redirect_uri})
|
|
361
|
+
stub_request(:put, redirect_uri).
|
|
362
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
363
|
+
to_return(status: 200, body: '', headers: {})
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
it "preserves the verb" do
|
|
367
|
+
expect(HTTP).to receive(:put).with(request_uri).and_call_original.ordered
|
|
368
|
+
expect(HTTP).to receive(:put).with(redirect_uri, '', {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original.ordered
|
|
369
|
+
response = HTTP.put(request_uri)
|
|
370
|
+
expect(response.success?).to eq(true)
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
|
|
353
374
|
context "no_redirect true" do
|
|
354
375
|
let(:request_uri){'http://example.com/path'}
|
|
355
376
|
let(:redirect_uri){'http://redirected.com'}
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,4 +3,13 @@
|
|
|
3
3
|
lib_dir = File.expand_path(File.join(__FILE__, '..', '..', 'lib'))
|
|
4
4
|
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
5
5
|
|
|
6
|
+
# Skip webmock's http_rb adapter: it auto-requires 'http', which collides
|
|
7
|
+
# with this gem's lib/HTTP.rb on case-insensitive filesystems and crashes
|
|
8
|
+
# while trying to monkey-patch the wrong HTTP module.
|
|
9
|
+
gem 'webmock'
|
|
10
|
+
$LOADED_FEATURES << File.join(
|
|
11
|
+
Gem.loaded_specs['webmock'].full_gem_path,
|
|
12
|
+
'lib/webmock/http_lib_adapters/http_rb_adapter.rb'
|
|
13
|
+
)
|
|
14
|
+
|
|
6
15
|
require 'webmock/rspec'
|