http.rb 1.3.9 → 1.3.10
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 +12 -0
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/request.rb +3 -8
- data/test/HTTP/REDIRECT_test.rb +18 -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: 873748118e3dfd0adeeccf8c1fe6db2e407eb2f6c34515bbc3fafbdf332e8b7b
|
|
4
|
+
data.tar.gz: 9a9df13975fdacee8e5e9933e5ed31fed099fa4d0601e722a805fa60048a7cf0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46f719719823a8e30ec6e5690973f10ab6f8ea81037d1083079a8ae574a0ed311ebb378dbf452c5667b649bf50a333497342e751677f4f35d14f27493c6f57ab
|
|
7
|
+
data.tar.gz: 0cc192a342f6c171d38b6338996aac5f96369e59ced845c0171048253d1ee44b5efe5bc67ec4fa19e5f9ca4d759949785156196832ff751f597d41f1ae09a5c5
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20261011
|
|
4
|
+
|
|
5
|
+
1.3.10: A block is yielded to once, with the response.
|
|
6
|
+
|
|
7
|
+
With a block, a followed redirect yielded the final response to it, and then yielded again whatever the block had returned, since that is what the redirected request returned and it was taken for the response: a block which returned an Array was handed that Array. With no_redirect set, the block was yielded the redirect and the redirect was then followed regardless, the branch yielding without returning, so the block was yielded to three times and a request was made which had been asked not to be.
|
|
8
|
+
|
|
9
|
+
1. ~ HTTP.request: a followed redirect returns what the redirected request returns, which has already been yielded where there is a block, rather than yielding it again.
|
|
10
|
+
2. ~ HTTP.request: no_redirect is a condition of following rather than a branch of its own, so that the redirect is yielded or returned as any other response is, and not followed.
|
|
11
|
+
3. ~ test/HTTP/REDIRECT_test.rb: + one yield with the final response when a redirect is followed, and one with the redirect when no_redirect is set. Both fail against 1.3.9.
|
|
12
|
+
4. ~ HTTP::VERSION: /1.3.9/1.3.10/
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## 20261011
|
|
4
16
|
|
|
5
17
|
1.3.9: Only a 301, 302, 303, 307, or 308 with a Location is followed.
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/request.rb
CHANGED
|
@@ -40,19 +40,14 @@ module HTTP
|
|
|
40
40
|
http.request(request_object)
|
|
41
41
|
end
|
|
42
42
|
)
|
|
43
|
-
if redirect?(response)
|
|
44
|
-
if block_given? && no_redirect
|
|
45
|
-
yield response
|
|
46
|
-
elsif no_redirect
|
|
47
|
-
return response
|
|
48
|
-
end
|
|
43
|
+
if !no_redirect && redirect?(response)
|
|
49
44
|
redirect_uri = uri.merge(response['location'])
|
|
50
45
|
onward_options = redirect_options(given_options, uri, redirect_uri)
|
|
51
46
|
if response.code =~ /^30[78]$/
|
|
52
47
|
data = METHODS::WITH_BODY.include?(request_method) ? request_object.body : {}
|
|
53
|
-
|
|
48
|
+
return send(request_method, redirect_uri.to_s, data, redirect_headers(headers, uri, redirect_uri), onward_options, &block)
|
|
54
49
|
else
|
|
55
|
-
|
|
50
|
+
return get(redirect_uri.to_s, {}, redirect_headers(headers, uri, redirect_uri, drop_content_type: true), onward_options, &block)
|
|
56
51
|
end
|
|
57
52
|
end
|
|
58
53
|
if block_given?
|
data/test/HTTP/REDIRECT_test.rb
CHANGED
|
@@ -111,4 +111,22 @@ describe "redirect behaviour" do
|
|
|
111
111
|
_(HTTP.get(uri).code).must_equal('302')
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
|
+
|
|
115
|
+
describe "with a block" do
|
|
116
|
+
it "yields once when a redirect is followed" do
|
|
117
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => other_origin_uri})
|
|
118
|
+
stub_request(:get, other_origin_uri).to_return(status: 200)
|
|
119
|
+
yielded = []
|
|
120
|
+
HTTP.get(uri){|response| yielded << response.code}
|
|
121
|
+
_(yielded).must_equal(['200'])
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "yields once, with the redirect, when no_redirect is set" do
|
|
125
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => other_origin_uri})
|
|
126
|
+
yielded = []
|
|
127
|
+
HTTP.get(uri, {}, {}, {no_redirect: true}){|response| yielded << response.code}
|
|
128
|
+
_(yielded).must_equal(['302'])
|
|
129
|
+
assert_not_requested(:get, other_origin_uri)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
114
132
|
end
|