http.rb 1.3.6 → 1.3.7
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 +13 -0
- data/lib/HTTP/REDIRECT.rb +6 -0
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/request.rb +5 -2
- data/test/HTTP/REDIRECT_test.rb +42 -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: 6d2e0827d0ee0a2f4215eabfd6cd2f952bacb1d12dc657ab1a488ef85a91a46f
|
|
4
|
+
data.tar.gz: 5d343996ad5cba48c51c9df5c7f0b31895f3a437d8be6cc15d5fdaff64075430
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 644e855a9c30b1ec23e0f2b3db27850ad9018574b37d1e25bcb63ce3aa11371d81a7a372c56cbd9c8f1a284ecf2cdaa0f7219b331da32c3d2fd3b6f4ea90df73
|
|
7
|
+
data.tar.gz: 751e3dfc085e8e9c1af0fc372bf948404fd6ac4839eb79ada5d38f390ea9a35ec6ce51381deda5ede866a10f6dafbe208a24ad23b4b15d143fad51a9d557c429
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20261011
|
|
4
|
+
|
|
5
|
+
1.3.7: The options hash is no longer altered, so no_redirect, retries, and basic authentication survive a call and a redirect.
|
|
6
|
+
|
|
7
|
+
HTTP.request took no_redirect, username, password, and the retry options out of the caller's hash with delete. A hash passed twice had lost no_redirect by the second call, which then followed the redirect it was asked not to. And the redirect was made with what was left of the hash, so retries and basic authentication were lost at the first redirect, even to the same origin.
|
|
8
|
+
|
|
9
|
+
1. ~ HTTP.request: works on a copy of the options hash, leaving the caller's as it was.
|
|
10
|
+
2. ~ HTTP.request: a redirect is made with the options as given, less what goes no further than the origin.
|
|
11
|
+
3. ~ lib/HTTP/REDIRECT.rb: + HTTP.redirect_options, which drops username and password where a redirect goes to another origin, as 1.3.6 does the credential headers.
|
|
12
|
+
4. ~ test/HTTP/REDIRECT_test.rb: + the options hash left as it was, no_redirect kept for a second call, retries kept after a redirect, and basic authentication kept for the same origin and dropped for another. All but the last fail against 1.3.6, which dropped it for every origin.
|
|
13
|
+
5. ~ HTTP::VERSION: /1.3.6/1.3.7/
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## 20261011
|
|
4
17
|
|
|
5
18
|
1.3.6: Authorization and Cookie headers go no further than the origin they were given to.
|
data/lib/HTTP/REDIRECT.rb
CHANGED
|
@@ -17,4 +17,10 @@ module HTTP
|
|
|
17
17
|
headers.reject{|k, v| REDIRECT::CREDENTIAL_HEADERS.include?(k.downcase)}
|
|
18
18
|
end
|
|
19
19
|
module_function :redirect_headers
|
|
20
|
+
|
|
21
|
+
def redirect_options(options, from_uri, to_uri)
|
|
22
|
+
return options if same_origin?(from_uri, to_uri)
|
|
23
|
+
options.reject{|k, v| %i{username password}.include?(k)}
|
|
24
|
+
end
|
|
25
|
+
module_function :redirect_options
|
|
20
26
|
end
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/request.rb
CHANGED
|
@@ -16,6 +16,8 @@ module HTTP
|
|
|
16
16
|
def request(uri, request_object, headers = {}, options = {}, &block)
|
|
17
17
|
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
18
18
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
19
|
+
given_options = options
|
|
20
|
+
options = options.dup
|
|
19
21
|
no_redirect = options.delete(:no_redirect)
|
|
20
22
|
username = options.delete(:username)
|
|
21
23
|
password = options.delete(:password)
|
|
@@ -45,11 +47,12 @@ module HTTP
|
|
|
45
47
|
return response
|
|
46
48
|
end
|
|
47
49
|
redirect_uri = uri.merge(response['location'])
|
|
50
|
+
onward_options = redirect_options(given_options, uri, redirect_uri)
|
|
48
51
|
if response.code =~ /^30[78]$/
|
|
49
52
|
data = METHODS::WITH_BODY.include?(request_method) ? request_object.body : {}
|
|
50
|
-
response = send(request_method, redirect_uri.to_s, data, redirect_headers(headers, uri, redirect_uri),
|
|
53
|
+
response = send(request_method, redirect_uri.to_s, data, redirect_headers(headers, uri, redirect_uri), onward_options, &block)
|
|
51
54
|
else
|
|
52
|
-
response = get(redirect_uri.to_s, {}, {},
|
|
55
|
+
response = get(redirect_uri.to_s, {}, {}, onward_options, &block)
|
|
53
56
|
end
|
|
54
57
|
end
|
|
55
58
|
if block_given?
|
data/test/HTTP/REDIRECT_test.rb
CHANGED
|
@@ -37,4 +37,46 @@ describe "redirect behaviour" do
|
|
|
37
37
|
assert_requested(:get, 'http://example.com:8080/path'){|request| !request.headers.key?('Cookie')}
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
describe "the options hash" do
|
|
42
|
+
it "is not altered by a call" do
|
|
43
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => same_origin_uri})
|
|
44
|
+
stub_request(:get, same_origin_uri).to_return(status: 200)
|
|
45
|
+
options = {no_redirect: false, username: 'alice', password: 'secret', retries: 1}
|
|
46
|
+
HTTP.get(uri, {}, {}, options)
|
|
47
|
+
_(options).must_equal({no_redirect: false, username: 'alice', password: 'secret', retries: 1})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "keeps no_redirect for a second call" do
|
|
51
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => other_origin_uri})
|
|
52
|
+
options = {no_redirect: true}
|
|
53
|
+
HTTP.get(uri, {}, {}, options)
|
|
54
|
+
_(HTTP.get(uri, {}, {}, options).redirection?).must_equal(true)
|
|
55
|
+
assert_not_requested(:get, other_origin_uri)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "keeps retrying after a redirect" do
|
|
59
|
+
HTTP::RETRY.stub(:sleep, nil) do
|
|
60
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => same_origin_uri})
|
|
61
|
+
stub_request(:get, same_origin_uri).to_return(status: 503).then.to_return(status: 200)
|
|
62
|
+
_(HTTP.get(uri, {}, {}, {retries: 1}).success?).must_equal(true)
|
|
63
|
+
assert_requested(:get, same_origin_uri, times: 2)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "basic authentication options" do
|
|
69
|
+
it "are kept for the same origin" do
|
|
70
|
+
stub_request(:get, uri).with(basic_auth: ['alice', 'secret']).to_return(status: 302, headers: {'location' => same_origin_uri})
|
|
71
|
+
stub_request(:get, same_origin_uri).with(basic_auth: ['alice', 'secret']).to_return(status: 200)
|
|
72
|
+
_(HTTP.get(uri, {}, {}, {username: 'alice', password: 'secret'}).success?).must_equal(true)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "are dropped for another origin" do
|
|
76
|
+
stub_request(:get, uri).with(basic_auth: ['alice', 'secret']).to_return(status: 307, headers: {'location' => other_origin_uri})
|
|
77
|
+
stub_request(:get, other_origin_uri).to_return(status: 200)
|
|
78
|
+
HTTP.get(uri, {}, {}, {username: 'alice', password: 'secret'})
|
|
79
|
+
assert_requested(:get, other_origin_uri){|request| !request.headers.key?('Authorization')}
|
|
80
|
+
end
|
|
81
|
+
end
|
|
40
82
|
end
|