http.rb 0.18.2 → 0.18.3
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 +10 -0
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/request.rb +7 -1
- data/spec/HTTP/delete_spec.rb +21 -0
- data/spec/HTTP/post_spec.rb +62 -0
- data/spec/HTTP/put_spec.rb +21 -0
- 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: 4bfdcd1317baede9f978ecc2090b816da19fd76531ab759ff685ffc42e237297
|
|
4
|
+
data.tar.gz: a4ea5421285e8a5b1b702b33be58de8be2e8984963b238b81679fdbca118eeec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5dbf7b38407e2bcc6932efdee8b36ee4994cdfc420edcb6d2c7f39d9a7c407af2c2b786424d0b33123e4538b7aa094e7ed0ea5597d1afbe392aad913b29e890c
|
|
7
|
+
data.tar.gz: ad271ead133a0f244d4f1538ee78aa2f6595c0a0c7be47bbf5d965f8768136f579354a1d4015754e0d60e922e64ade6cbc9043213d63d006c50e140e3c196553
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
# 20260521
|
|
4
|
+
# 0.18.3: Fix verb preservation on 307/308 redirects.
|
|
5
|
+
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.
|
|
6
|
+
2. ~ spec/HTTP/post_spec.rb: + specs for 307/308 verb preservation and 307 body preservation.
|
|
7
|
+
3. ~ spec/HTTP/put_spec.rb: + spec for 307 verb preservation.
|
|
8
|
+
4. ~ spec/HTTP/delete_spec.rb: + spec for 307 verb preservation.
|
|
9
|
+
5. ~ spec/spec_helper.rb: Skip webmock's http_rb adapter, which collides with this gem's HTTP module on case-insensitive filesystems.
|
|
10
|
+
6. ~ HTTP::VERSION: /0.18.2/0.18.3/
|
|
11
|
+
7. ~ CHANGELOG: + 0.18.3 entry
|
|
12
|
+
|
|
3
13
|
# 20260520
|
|
4
14
|
# 0.18.2: Fix relative redirect URL construction.
|
|
5
15
|
1. ~ HTTP.request: Use URI#merge for redirect URL construction. Preserves original scheme, elides default ports, and resolves relative paths per RFC 3986.
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/request.rb
CHANGED
|
@@ -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
|
@@ -212,6 +212,27 @@ describe ".delete" do
|
|
|
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: 0}).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/post_spec.rb
CHANGED
|
@@ -350,6 +350,68 @@ describe ".post" do
|
|
|
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: 0}).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: 0}).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
|
@@ -350,6 +350,27 @@ describe ".put" do
|
|
|
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: 0}).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'
|