http.rb 1.5.0 → 1.7.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 +25 -1
- data/README.md +9 -0
- data/lib/HTTP/REDIRECT.rb +11 -1
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/request.rb +1 -0
- data/lib/{HTTP.rb → http.rb} +1 -1
- data/test/HTTP/REDIRECT_test.rb +24 -0
- data/test/helper.rb +11 -8
- data/test/loading_test.rb +30 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a0a461fdf56bdea8f5f4b1940f0af469ef67e3fd7bd1319cc33245ff50641bb
|
|
4
|
+
data.tar.gz: 45e533a1a9cf2934d78cc8b6f29e58e4a73e8d26485a1cef12ad98f4be04b9e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73bc96382cf88af02f52f48e36d004e9b1dfee91e658700495f712632d55793f1543e253bdcccca09c6bda7fc71c59d61448818f89b8b8fc1a355becfd5d3ffb
|
|
7
|
+
data.tar.gz: 814f7dcd3026a55a675c87d311b8e724f843895768c996c4e4c5f3283c38a81f46d03934256fa832835135229a042439655261a649bccec07cb5e8189006a010
|
data/CHANGELOG
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
# CHANGELOG
|
|
1
|
+
# http/CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 20261018
|
|
4
|
+
|
|
5
|
+
1.7.0: lib/HTTP.rb --> lib/http.rb
|
|
6
|
+
|
|
7
|
+
1. lib/HTTP.rb --> lib/http.rb, so that it resolves the same on case-sensitive filesystems.
|
|
8
|
+
2. + test/loading_test.rb: lib/ carries http.rb, and require 'http.rb' in a fresh process defines HTTP and HTTP::VERSION.
|
|
9
|
+
3. ~ test/helper.rb: + skip_webmocks_http_rb_adapter()
|
|
10
|
+
4. ~ HTTP::VERSION: /1.6.0/1.7.0/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 20261011
|
|
14
|
+
|
|
15
|
+
1.6.0: The response's uri is the URI it came from, which, where redirects were followed, is where they ended.
|
|
16
|
+
|
|
17
|
+
Nothing recorded where a response had come from: the request objects are made from a path rather than a URI, so Net::HTTP left response.uri nil, and a caller whose request was redirected had no way of knowing where to. A spider resolving the links on a page against the page's address needs it, as does anything noticing that it has been sent to a login page.
|
|
18
|
+
|
|
19
|
+
1. ~ lib/HTTP/REDIRECT.rb: + HTTP.response_uri, which leaves out any credentials embedded in the URI, a response being something which is passed around and printed.
|
|
20
|
+
2. ~ HTTP.request: response.uri is set to response_uri of the URI requested, so that after redirects it is the last of them.
|
|
21
|
+
3. ~ HTTP::TooManyRedirects: the message names the URI of the redirect not followed as well as its Location.
|
|
22
|
+
4. ~ test/HTTP/REDIRECT_test.rb: + the final URI without a redirect, after one, with no_redirect, and without embedded credentials; the URI of the redirect TooManyRedirects carries. All fail against 1.5.0.
|
|
23
|
+
5. ~ README.md: + the response's uri, under Redirections, and in the Limiting redirections example.
|
|
24
|
+
6. ~ HTTP::VERSION: /1.5.0/1.6.0/
|
|
25
|
+
|
|
2
26
|
|
|
3
27
|
## 20261011
|
|
4
28
|
|
data/README.md
CHANGED
|
@@ -112,6 +112,14 @@ A body repeated keeps its `Content-Type`, form data's included. Where the method
|
|
|
112
112
|
|
|
113
113
|
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.
|
|
114
114
|
|
|
115
|
+
The response's `uri` is the URI it came from, which, where redirects were followed, is where they ended:
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
response = HTTP.get('http://example.com/moved')
|
|
119
|
+
response.uri
|
|
120
|
+
# => #<URI::HTTP http://example.com/new_location>
|
|
121
|
+
```
|
|
122
|
+
|
|
115
123
|
### Preventing redirections
|
|
116
124
|
|
|
117
125
|
```ruby
|
|
@@ -129,6 +137,7 @@ HTTP.get('http://example.com', {}, {}, {max_redirects: 5})
|
|
|
129
137
|
begin
|
|
130
138
|
HTTP.get('http://example.com/loop')
|
|
131
139
|
rescue HTTP::TooManyRedirects => e
|
|
140
|
+
e.response.uri
|
|
132
141
|
e.response['location']
|
|
133
142
|
end
|
|
134
143
|
```
|
data/lib/HTTP/REDIRECT.rb
CHANGED
|
@@ -13,7 +13,7 @@ module HTTP
|
|
|
13
13
|
|
|
14
14
|
def initialize(response)
|
|
15
15
|
@response = response
|
|
16
|
-
super("Too many redirects: #{response.code} to #{response['location']}")
|
|
16
|
+
super("Too many redirects: #{response.code} from #{response.uri} to #{response['location']}")
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -68,4 +68,14 @@ module HTTP
|
|
|
68
68
|
options.reject{|k, v| %i{username password}.include?(k)}
|
|
69
69
|
end
|
|
70
70
|
module_function :redirect_options
|
|
71
|
+
|
|
72
|
+
# Embedded credentials are left out, a response being something which is passed
|
|
73
|
+
# around and printed. URI#userinfo= ignores nil, whereas URI#user= takes the password
|
|
74
|
+
# with it.
|
|
75
|
+
def response_uri(uri)
|
|
76
|
+
uri = uri.dup
|
|
77
|
+
uri.user = nil if uri.user
|
|
78
|
+
uri
|
|
79
|
+
end
|
|
80
|
+
module_function :response_uri
|
|
71
81
|
end
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/request.rb
CHANGED
data/lib/{HTTP.rb → http.rb}
RENAMED
data/test/HTTP/REDIRECT_test.rb
CHANGED
|
@@ -7,6 +7,29 @@ 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 "the final URI" do
|
|
11
|
+
it "is the requested URI when there is no redirect" do
|
|
12
|
+
stub_request(:get, uri).to_return(status: 200)
|
|
13
|
+
_(HTTP.get(uri).uri.to_s).must_equal(uri)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "is the URI redirected to when a redirect is followed" do
|
|
17
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => other_origin_uri})
|
|
18
|
+
stub_request(:get, other_origin_uri).to_return(status: 200)
|
|
19
|
+
_(HTTP.get(uri).uri.to_s).must_equal(other_origin_uri)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "is the URI which redirected when no_redirect is set" do
|
|
23
|
+
stub_request(:get, uri).to_return(status: 302, headers: {'location' => other_origin_uri})
|
|
24
|
+
_(HTTP.get(uri, {}, {}, {no_redirect: true}).uri.to_s).must_equal(uri)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "carries no embedded credentials" do
|
|
28
|
+
stub_request(:get, uri).with(basic_auth: ['alice', 'secret']).to_return(status: 200)
|
|
29
|
+
_(HTTP.get('http://alice:secret@example.com/path').uri.to_s).must_equal(uri)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
10
33
|
describe "headers" do
|
|
11
34
|
%w{301 302 303 307 308}.each do |code|
|
|
12
35
|
it "are carried through a #{code}" do
|
|
@@ -230,6 +253,7 @@ describe "redirect behaviour" do
|
|
|
230
253
|
it "raises TooManyRedirects, with the redirect not followed, when there are more" do
|
|
231
254
|
error = _(->{HTTP.get('http://example.com/0', {}, {}, {max_redirects: 1})}).must_raise(HTTP::TooManyRedirects)
|
|
232
255
|
_(error.response['location']).must_equal('/2')
|
|
256
|
+
_(error.response.uri.to_s).must_equal('http://example.com/1')
|
|
233
257
|
assert_not_requested(:get, 'http://example.com/2')
|
|
234
258
|
end
|
|
235
259
|
|
data/test/helper.rb
CHANGED
|
@@ -3,16 +3,19 @@
|
|
|
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
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
6
|
+
# webmock's http_rb adapter's require 'http' finds this gem's lib/http.rb,
|
|
7
|
+
# takes HTTP::VERSION for the http gem's, and crashes trying to
|
|
8
|
+
# monkey-patch an HTTP::Client which isn't there.
|
|
9
|
+
def skip_webmocks_http_rb_adapter
|
|
10
|
+
gem 'webmock'
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
$LOADED_FEATURES << File.join(
|
|
13
|
+
Gem.loaded_specs['webmock'].full_gem_path,
|
|
14
|
+
'lib/webmock/http_lib_adapters/http_rb_adapter.rb'
|
|
15
|
+
)
|
|
16
|
+
end
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
Gem.loaded_specs['webmock'].full_gem_path,
|
|
14
|
-
'lib/webmock/http_lib_adapters/http_rb_adapter.rb'
|
|
15
|
-
)
|
|
18
|
+
skip_webmocks_http_rb_adapter
|
|
16
19
|
|
|
17
20
|
require 'minitest/autorun'
|
|
18
21
|
require 'minitest/mock'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# test/loading_test.rb
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/http'
|
|
6
|
+
|
|
7
|
+
# In its own process, since this one has loaded the file directly and so could
|
|
8
|
+
# not tell what requiring the gem by its own name would bring.
|
|
9
|
+
describe 'loading' do
|
|
10
|
+
def ruby(source)
|
|
11
|
+
lib = File.expand_path('../lib', __dir__)
|
|
12
|
+
IO.popen(['ruby', "-I#{lib}", '-e', source], err: [:child, :out]){|io| io.read}.strip
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# The gem is http.rb, so require 'http.rb' reads lib/http.rb. A capitalised
|
|
16
|
+
# load file answers that only on a case-insensitive filesystem. Dir.entries
|
|
17
|
+
# reports the name as stored, so this asks what a case-sensitive filesystem
|
|
18
|
+
# would ask.
|
|
19
|
+
it "carries the lowercase file the gem's name asks for" do
|
|
20
|
+
_(Dir.entries(File.expand_path('../lib', __dir__))).must_include 'http.rb'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "defines HTTP upon requiring the gem by name" do
|
|
24
|
+
_(ruby('require "http.rb"; print defined?(HTTP)')).must_equal 'constant'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "defines the version too" do
|
|
28
|
+
_(ruby('require "http.rb"; print HTTP::VERSION')).must_equal HTTP::VERSION
|
|
29
|
+
end
|
|
30
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -93,7 +93,6 @@ files:
|
|
|
93
93
|
- README.md
|
|
94
94
|
- Rakefile
|
|
95
95
|
- http.rb.gemspec
|
|
96
|
-
- lib/HTTP.rb
|
|
97
96
|
- lib/HTTP/METHODS.rb
|
|
98
97
|
- lib/HTTP/REDIRECT.rb
|
|
99
98
|
- lib/HTTP/RETRY.rb
|
|
@@ -108,6 +107,7 @@ files:
|
|
|
108
107
|
- lib/Thoran/Hash/XWwwFormUrlencode/x_www_form_urlencode.rb
|
|
109
108
|
- lib/Thoran/String/Urlencode/urlencode.rb
|
|
110
109
|
- lib/URI/Generic/use_sslQ.rb
|
|
110
|
+
- lib/http.rb
|
|
111
111
|
- test/HTTP/METHODS_test.rb
|
|
112
112
|
- test/HTTP/REDIRECT_test.rb
|
|
113
113
|
- test/HTTP/RETRY_test.rb
|
|
@@ -126,6 +126,7 @@ files:
|
|
|
126
126
|
- test/Net/HTTPResponse/StatusPredicates_test.rb
|
|
127
127
|
- test/Thoran/String/Urlencode/urlencode_test.rb
|
|
128
128
|
- test/helper.rb
|
|
129
|
+
- test/loading_test.rb
|
|
129
130
|
homepage: https://github.com/thoran/http
|
|
130
131
|
licenses:
|
|
131
132
|
- MIT
|