http.rb 1.3.7 → 1.3.8
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/README.md +4 -0
- data/lib/HTTP/REDIRECT.rb +6 -3
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/request.rb +1 -1
- data/test/HTTP/REDIRECT_test.rb +18 -1
- 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: 5cab4dfd9757c08463389bff8595489378a59ecb3149cbdfcc465ab6a508536e
|
|
4
|
+
data.tar.gz: 5fe112a78858fc9deee9a1b8ab29cf71325a7e0801fd6b6d33e3f48835aba2dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9678a45ae024d10874c9fdd9781e785b64f2e9818c85cc991b7af6bff8f56d38d3cad1f53d606bf36ff758581a1c2106e3b38c5f88224aa6d5272833ee97482
|
|
7
|
+
data.tar.gz: 8f9c36f7f2496a752c55a3352eb867585e787d72d63e87c8a124576b849517e213bd997d92415d2819eaac3f21a47099bef2f3a2f8e85e473aea6d8a3c9ab560
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20261011
|
|
4
|
+
|
|
5
|
+
1.3.8: Headers are carried through a 301, 302, or 303.
|
|
6
|
+
|
|
7
|
+
A 301, 302, or 303 was followed with no headers at all, so a User-Agent, an Accept, or a Cookie given to the request was not sent to where it was redirected, whereas a 307 or 308 sent them all. Now every redirect carries them, less the credentials which 1.3.6 keeps to their origin, and less Content-Type where the request is made a GET, there being no body for it to describe.
|
|
8
|
+
|
|
9
|
+
1. ~ HTTP.redirect_headers: + drop_content_type:, which leaves Content-Type behind.
|
|
10
|
+
2. ~ HTTP.request: a 301, 302, or 303 is followed with redirect_headers, dropping Content-Type, rather than with no headers.
|
|
11
|
+
3. ~ test/HTTP/REDIRECT_test.rb: + headers carried through each of 301, 302, 303, 307, and 308, and Content-Type left behind when a POST becomes a GET; credentials dropped for another origin by 301, 302, and 303 as well as by 307 and 308. The 301, 302, and 303 examples fail against 1.3.7.
|
|
12
|
+
4. ~ README.md: + Redirections, on what is carried through a redirect and what is not.
|
|
13
|
+
5. ~ HTTP::VERSION: /1.3.7/1.3.8/
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## 20261011
|
|
4
17
|
|
|
5
18
|
1.3.7: The options hash is no longer altered, so no_redirect, retries, and basic authentication survive a call and a redirect.
|
data/README.md
CHANGED
|
@@ -93,6 +93,10 @@ HTTP.get('http://alice:secret@example.com')
|
|
|
93
93
|
|
|
94
94
|
When both are supplied, the options hash wins.
|
|
95
95
|
|
|
96
|
+
### Redirections
|
|
97
|
+
|
|
98
|
+
Redirects are followed with the headers they were given, except that `Authorization` and `Cookie`, and the `username:` and `password:` options, go no further than the origin (scheme, host, and port) they were given to. Where a redirect makes the request a GET, `Content-Type` is left behind, there being no body for it to describe.
|
|
99
|
+
|
|
96
100
|
### Preventing redirections
|
|
97
101
|
|
|
98
102
|
```ruby
|
data/lib/HTTP/REDIRECT.rb
CHANGED
|
@@ -12,9 +12,12 @@ module HTTP
|
|
|
12
12
|
module_function :same_origin?
|
|
13
13
|
|
|
14
14
|
# Credentials are for the origin they were given to, so they go no further than it.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
headers.reject
|
|
15
|
+
# A request made into a GET has no body for a Content-Type to describe.
|
|
16
|
+
def redirect_headers(headers, from_uri, to_uri, drop_content_type: false)
|
|
17
|
+
headers.reject do |k, v|
|
|
18
|
+
(drop_content_type && k.downcase == 'content-type') ||
|
|
19
|
+
(!same_origin?(from_uri, to_uri) && REDIRECT::CREDENTIAL_HEADERS.include?(k.downcase))
|
|
20
|
+
end
|
|
18
21
|
end
|
|
19
22
|
module_function :redirect_headers
|
|
20
23
|
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/request.rb
CHANGED
|
@@ -52,7 +52,7 @@ module HTTP
|
|
|
52
52
|
data = METHODS::WITH_BODY.include?(request_method) ? request_object.body : {}
|
|
53
53
|
response = send(request_method, redirect_uri.to_s, data, redirect_headers(headers, uri, redirect_uri), onward_options, &block)
|
|
54
54
|
else
|
|
55
|
-
response = get(redirect_uri.to_s, {},
|
|
55
|
+
response = get(redirect_uri.to_s, {}, redirect_headers(headers, uri, redirect_uri, drop_content_type: true), onward_options, &block)
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
if block_given?
|
data/test/HTTP/REDIRECT_test.rb
CHANGED
|
@@ -7,6 +7,23 @@ describe "redirect behaviour" do
|
|
|
7
7
|
let(:same_origin_uri){'http://example.com/elsewhere'}
|
|
8
8
|
let(:other_origin_uri){'http://redirected.com/path'}
|
|
9
9
|
|
|
10
|
+
describe "headers" do
|
|
11
|
+
%w{301 302 303 307 308}.each do |code|
|
|
12
|
+
it "are carried through a #{code}" do
|
|
13
|
+
stub_request(:get, uri).to_return(status: code.to_i, headers: {'location' => other_origin_uri})
|
|
14
|
+
stub_request(:get, other_origin_uri).with(headers: {'User-Agent' => 'Redback', 'Accept' => 'text/html'}).to_return(status: 200)
|
|
15
|
+
_(HTTP.get(uri, {}, {'User-Agent' => 'Redback', 'Accept' => 'text/html'}).success?).must_equal(true)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "leave Content-Type behind when a POST becomes a GET" do
|
|
20
|
+
stub_request(:post, uri).to_return(status: 303, headers: {'location' => same_origin_uri})
|
|
21
|
+
stub_request(:get, same_origin_uri).to_return(status: 200)
|
|
22
|
+
HTTP.post(uri, {a: 1}, {'Content-Type' => 'application/json', 'User-Agent' => 'Redback'})
|
|
23
|
+
assert_requested(:get, same_origin_uri){|request| !request.headers.key?('Content-Type') && request.headers['User-Agent'] == 'Redback'}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
10
27
|
describe "credentials" do
|
|
11
28
|
it "are kept for the same origin" do
|
|
12
29
|
stub_request(:get, uri).to_return(status: 307, headers: {'location' => same_origin_uri})
|
|
@@ -14,7 +31,7 @@ describe "redirect behaviour" do
|
|
|
14
31
|
_(HTTP.get(uri, {}, {'Authorization' => 'Bearer x', 'Cookie' => 'session=1'}).success?).must_equal(true)
|
|
15
32
|
end
|
|
16
33
|
|
|
17
|
-
%w{307 308}.each do |code|
|
|
34
|
+
%w{301 302 303 307 308}.each do |code|
|
|
18
35
|
it "are dropped for another origin via #{code}" do
|
|
19
36
|
stub_request(:get, uri).to_return(status: code.to_i, headers: {'location' => other_origin_uri})
|
|
20
37
|
stub_request(:get, other_origin_uri).to_return(status: 200)
|