http.rb 1.3.11 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4df4290326561e27192344f8c932e0e6df4474080d8f2986c89591abb87ce7b2
4
- data.tar.gz: ad38951e186650e88d4ff40dc3ce646cd5932d1c779a869c0842f642e0d15c70
3
+ metadata.gz: 72cf60480847b43b60b63378d803acae19a12c127ceb9695ed8b0eca99ca57a4
4
+ data.tar.gz: aed0e179795a1f408823cb5cecca6bb2c877a1e4a90c3a31f21a115a5270a2e6
5
5
  SHA512:
6
- metadata.gz: 34cbe673b63634c80b6acdcbac2be9cd4d72687a50a4fdc3e9412d004eda92975bf72cf3699e1a65f71221519d79255232b7af22360388434cf6b874b16a33cb
7
- data.tar.gz: f09778ee10dc83dfc30047965b9c5d8ca3a671c1af19c4146d2241a8a5b7675b2aff3ac3025bd49bb58b4f94428373f2a1d6cb47a4d056ac119561c9ba9ded4f
6
+ metadata.gz: b8e095a766f24d074324536e89dc07871bc8670785fe14f95470a06e64a4107e0c7c2df44f746c8dbd9c31d7b79336e8548aaf5601e4121db86f5787c1ee66bb
7
+ data.tar.gz: c5637e2490a1605d4112162bad17c12d70e1536af814901c1bdc2572eb730f15e54b0eb8db2db3ff6057d872b9969b7852c5767872b9108ce257a160a9ebf24f
data/CHANGELOG CHANGED
@@ -1,5 +1,34 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 20261011
4
+
5
+ 1.5.0: + max_redirects; + HTTP::TooManyRedirects.
6
+
7
+ Redirects were followed without limit, each by a call nested in the last, so a redirect loop ran until SystemStackError, which against a local server came after 2,179 requests. Now no more than max_redirects are followed, 20 unless given, which is where browsers stop, and one more raises HTTP::TooManyRedirects.
8
+
9
+ 1. ~ lib/HTTP/REDIRECT.rb: + HTTP::REDIRECT::MAX (20); + HTTP::TooManyRedirects, whose response is the redirect which was not followed.
10
+ 2. ~ HTTP.redirect_options: + max_redirects, which the redirect is made with one fewer of.
11
+ 3. ~ HTTP.request: + max_redirects option, which defaults to HTTP::REDIRECT::MAX and is not passed through to Net::HTTP; HTTP::TooManyRedirects is raised at a redirect when none are left. max_redirects: 0 raises at the first redirect, where no_redirect: true returns it, and no_redirect wins where both are given.
12
+ 4. ~ test/HTTP/REDIRECT_test.rb: + as many redirects followed as allowed, TooManyRedirects for one more with the redirect not followed, 0 raising at the first, no_redirect winning over it, a loop stopped at the default, and the option not passed through to Net::HTTP; max_redirects among the options left as they were. All fail against 1.4.0, which passed max_redirects through to Net::HTTP, where there is no max_redirects= for it.
13
+ 5. ~ README.md: + Limiting redirections; + max_redirects among the options which aren't passed through to Net::HTTP.
14
+ 6. ~ HTTP::VERSION: /1.4.0/1.5.0/
15
+
16
+
17
+ ## 20261011
18
+
19
+ 1.4.0: The method on a redirect is as RFC 9110 has it: a DELETE redirected by a 301 or 302 is now a DELETE, a PUT a PUT, and a HEAD a HEAD.
20
+
21
+ Every 301, 302, and 303 was followed with a GET, whatever the method. RFC 9110 allows a 301 or 302 to make a POST a GET, for historical reasons, and nothing else: a PUT, a PATCH, a DELETE, an OPTIONS, or a TRACE was turned into a GET, which did something other than was asked, and a HEAD was too, which fetched the body a HEAD is made to avoid. A 303 does make the method a GET, except for a HEAD, which stays one. Those which were made a GET will now be repeated as themselves, a DELETE included, which is what the specification asks but which differs from what was done before, so anyone whose redirected DELETE, PUT, or PATCH was quietly becoming a GET will find it isn't.
22
+
23
+ 1. ~ lib/HTTP/REDIRECT.rb: + HTTP.redirect_method: 307 and 308 keep the method; 303 makes it a GET, a HEAD excepted; 301 and 302 make a POST a GET and keep the rest.
24
+ 2. ~ HTTP.request: a redirect is made with redirect_method, through request_with_body where the request had a body to repeat and request_without_body otherwise, rather than through the named method. Content-Type is left behind only where the method changes, and a body repeated keeps it through body_headers, as 1.3.11 has a 307 or 308 do, which matters the more now that a PUT or PATCH redirected by a 301 or 302 is repeated with its body rather than made a GET.
25
+ 3. ~ HTTP.request: a method without a named helper, such as PROPFIND made with request_without_body, is followed. A 307 or 308 was followed with send(request_method), which raised NoMethodError for one.
26
+ 4. ~ test/HTTP/{delete,head,options,patch,put,trace}_test.rb: a 301 or 302 is expected to be followed with the method itself rather than with GET.
27
+ 5. ~ test/HTTP/REDIRECT_test.rb: + the method through each of 301, 302, 303, 307, and 308: POST, PUT with its body, DELETE, HEAD, and PROPFIND. The ones which keep a method other than GET or POST fail against 1.3.11, and PROPFIND by 307 and 308 raised. The PUT examples assert its Content-Type as well as its body.
28
+ 6. ~ README.md: + how the method is kept, under Redirections, with a table of each method through each redirect.
29
+ 7. ~ HTTP::VERSION: /1.3.11/1.4.0/
30
+
31
+
3
32
  ## 20261011
4
33
 
5
34
  1.3.11: A repeated body keeps the Content-Type it was sent with.
data/README.md CHANGED
@@ -97,6 +97,19 @@ When both are supplied, the options hash wins.
97
97
 
98
98
  301, 302, 303, 307, and 308 responses with a `Location` are followed. Other 3xx responses, such as 300 and 304, are returned as they are.
99
99
 
100
+ The method is kept as RFC 9110 has it. 307 and 308 repeat the request as it was. 303 makes it a GET, except that a HEAD stays a HEAD. 301 and 302 make a POST a GET, as browsers do, and keep every other method:
101
+
102
+ | Method | 301, 302 | 303 | 307, 308 |
103
+ | --- | --- | --- | --- |
104
+ | GET | GET | GET | GET |
105
+ | HEAD | HEAD | HEAD | HEAD |
106
+ | POST | GET, without its body | GET, without its body | POST, with its body |
107
+ | PUT, PATCH | kept, with its body | GET, without its body | kept, with its body |
108
+ | DELETE, OPTIONS, TRACE | kept | GET | kept |
109
+ | Any other, such as PROPFIND | kept | GET | kept |
110
+
111
+ A body repeated keeps its `Content-Type`, form data's included. Where the method changes, `Content-Type` is left behind with the body.
112
+
100
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.
101
114
 
102
115
  ### Preventing redirections
@@ -106,6 +119,22 @@ HTTP.get('http://example.com', {}, {}, {no_redirect: true})
106
119
  # => #<Net::HTTPResponse @code=3xx>
107
120
  ```
108
121
 
122
+ ### Limiting redirections
123
+
124
+ Up to 20 redirects are followed by default. One more raises `HTTP::TooManyRedirects`, whose `response` is the redirect which wasn't followed:
125
+
126
+ ```ruby
127
+ HTTP.get('http://example.com', {}, {}, {max_redirects: 5})
128
+
129
+ begin
130
+ HTTP.get('http://example.com/loop')
131
+ rescue HTTP::TooManyRedirects => e
132
+ e.response['location']
133
+ end
134
+ ```
135
+
136
+ `max_redirects: 0` raises at the first redirect, whereas `no_redirect: true` returns it.
137
+
109
138
  ### Retries
110
139
 
111
140
  Retries are disabled by default. Enable them by passing `retries:` in the options hash.
@@ -203,12 +232,16 @@ HTTP.request_with_body(:propfind, 'http://example.com/path', xml, {'Content-Type
203
232
  Both take the same `(method, uri, args_or_data, headers, options, &block)` arguments as the named methods, with the method as the first argument, and the named methods delegate to them. For full control over the request object, drop down to `HTTP.request(uri, request_object, headers, options, &block)`.
204
233
 
205
234
  ## Allowed values for the options hash
206
- #### (These pass through to Net::HTTP, except for `no_redirect`, `username`, and `password`.)
235
+ #### (These pass through to Net::HTTP, except for `no_redirect`, `max_redirects`, `username`, and `password`.)
207
236
 
208
237
  ```Ruby
209
238
  no_redirect
210
239
  # Prevents redirection if a 3xx response is encountered.
211
240
 
241
+ max_redirects
242
+ # The most redirects followed before HTTP::TooManyRedirects is raised.
243
+ # Defaults to 20.
244
+
212
245
  username
213
246
  # Username for HTTP basic authentication. Takes precedence over any
214
247
  # credentials embedded in the URI.
data/lib/HTTP/REDIRECT.rb CHANGED
@@ -5,6 +5,16 @@ module HTTP
5
5
  module REDIRECT
6
6
  CODES = %w{301 302 303 307 308}.freeze
7
7
  CREDENTIAL_HEADERS = %w{authorization cookie}.freeze
8
+ MAX = 20
9
+ end
10
+
11
+ class TooManyRedirects < StandardError
12
+ attr_reader :response
13
+
14
+ def initialize(response)
15
+ @response = response
16
+ super("Too many redirects: #{response.code} to #{response['location']}")
17
+ end
8
18
  end
9
19
 
10
20
  # A 300 or a 304 is an answer rather than somewhere else to go, and a 3xx without a
@@ -14,6 +24,20 @@ module HTTP
14
24
  end
15
25
  module_function :redirect?
16
26
 
27
+ # 307 and 308 keep the method. 303 makes it a GET, a HEAD excepted. 301 and 302 make
28
+ # only a POST a GET, which RFC 9110 allows for historical reasons, and keep the rest.
29
+ def redirect_method(code, request_method)
30
+ case code
31
+ when '303'
32
+ request_method == :head ? :head : :get
33
+ when '301', '302'
34
+ request_method == :post ? :get : request_method
35
+ else
36
+ request_method
37
+ end
38
+ end
39
+ module_function :redirect_method
40
+
17
41
  def same_origin?(a, b)
18
42
  [a.scheme, a.host, a.port] == [b.scheme, b.host, b.port]
19
43
  end
@@ -38,7 +62,8 @@ module HTTP
38
62
  end
39
63
  module_function :body_headers
40
64
 
41
- def redirect_options(options, from_uri, to_uri)
65
+ def redirect_options(options, from_uri, to_uri, max_redirects)
66
+ options = options.merge(max_redirects: max_redirects - 1)
42
67
  return options if same_origin?(from_uri, to_uri)
43
68
  options.reject{|k, v| %i{username password}.include?(k)}
44
69
  end
data/lib/HTTP/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # HTTP::VERSION
3
3
 
4
4
  module HTTP
5
- VERSION = '1.3.11'
5
+ VERSION = '1.5.0'
6
6
  end
data/lib/HTTP/request.rb CHANGED
@@ -19,6 +19,7 @@ module HTTP
19
19
  given_options = options
20
20
  options = options.dup
21
21
  no_redirect = options.delete(:no_redirect)
22
+ max_redirects = options.delete(:max_redirects) || REDIRECT::MAX
22
23
  username = options.delete(:username)
23
24
  password = options.delete(:password)
24
25
  config = retry_config(options)
@@ -41,13 +42,16 @@ module HTTP
41
42
  end
42
43
  )
43
44
  if !no_redirect && redirect?(response)
45
+ raise TooManyRedirects.new(response) if max_redirects < 1
44
46
  redirect_uri = uri.merge(response['location'])
45
- onward_options = redirect_options(given_options, uri, redirect_uri)
46
- if response.code =~ /^30[78]$/
47
- data = METHODS::WITH_BODY.include?(request_method) ? request_object.body : {}
48
- return send(request_method, redirect_uri.to_s, data, redirect_headers(body_headers(headers, request_object), uri, redirect_uri), onward_options, &block)
47
+ onward_options = redirect_options(given_options, uri, redirect_uri, max_redirects)
48
+ redirect_method = redirect_method(response.code, request_method)
49
+ if redirect_method != request_method
50
+ return request_without_body(redirect_method, redirect_uri, {}, redirect_headers(headers, uri, redirect_uri, drop_content_type: true), onward_options, &block)
51
+ elsif request_object.body
52
+ return request_with_body(request_method, redirect_uri, request_object.body, redirect_headers(body_headers(headers, request_object), uri, redirect_uri), onward_options, &block)
49
53
  else
50
- return get(redirect_uri.to_s, {}, redirect_headers(headers, uri, redirect_uri, drop_content_type: true), onward_options, &block)
54
+ return request_without_body(request_method, redirect_uri, {}, redirect_headers(headers, uri, redirect_uri), onward_options, &block)
51
55
  end
52
56
  end
53
57
  if block_given?
@@ -59,9 +59,9 @@ describe "redirect behaviour" do
59
59
  it "is not altered by a call" do
60
60
  stub_request(:get, uri).to_return(status: 302, headers: {'location' => same_origin_uri})
61
61
  stub_request(:get, same_origin_uri).to_return(status: 200)
62
- options = {no_redirect: false, username: 'alice', password: 'secret', retries: 1}
62
+ options = {no_redirect: false, max_redirects: 3, username: 'alice', password: 'secret', retries: 1}
63
63
  HTTP.get(uri, {}, {}, options)
64
- _(options).must_equal({no_redirect: false, username: 'alice', password: 'secret', retries: 1})
64
+ _(options).must_equal({no_redirect: false, max_redirects: 3, username: 'alice', password: 'secret', retries: 1})
65
65
  end
66
66
 
67
67
  it "keeps no_redirect for a second call" do
@@ -145,4 +145,112 @@ describe "redirect behaviour" do
145
145
  _(HTTP.post(uri, {a: 1}, {'Content-Type' => 'application/json'}).success?).must_equal(true)
146
146
  end
147
147
  end
148
+
149
+ describe "the method" do
150
+ %w{301 302}.each do |code|
151
+ describe "via #{code}" do
152
+ it "makes a POST a GET" do
153
+ stub_request(:post, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
154
+ stub_request(:get, same_origin_uri).to_return(status: 200)
155
+ _(HTTP.post(uri, {a: 1}).success?).must_equal(true)
156
+ end
157
+
158
+ it "keeps a PUT, with its body and its Content-Type" do
159
+ stub_request(:put, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
160
+ stub_request(:put, same_origin_uri).with(body: 'a=1', headers: {'Content-Type' => 'application/x-www-form-urlencoded'}).to_return(status: 200)
161
+ _(HTTP.put(uri, {a: 1}).success?).must_equal(true)
162
+ end
163
+
164
+ it "keeps a DELETE" do
165
+ stub_request(:delete, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
166
+ stub_request(:delete, same_origin_uri).to_return(status: 200)
167
+ _(HTTP.delete(uri).success?).must_equal(true)
168
+ assert_not_requested(:get, same_origin_uri)
169
+ end
170
+
171
+ it "keeps a HEAD" do
172
+ stub_request(:head, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
173
+ stub_request(:head, same_origin_uri).to_return(status: 200)
174
+ _(HTTP.head(uri).success?).must_equal(true)
175
+ assert_not_requested(:get, same_origin_uri)
176
+ end
177
+
178
+ it "keeps a method without a named helper" do
179
+ stub_request(:propfind, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
180
+ stub_request(:propfind, same_origin_uri).to_return(status: 207)
181
+ _(HTTP.request_without_body(:propfind, uri).code).must_equal('207')
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "via 303" do
187
+ %i{post put delete}.each do |request_method|
188
+ it "makes a #{request_method.upcase} a GET" do
189
+ stub_request(request_method, uri).to_return(status: 303, headers: {'location' => same_origin_uri})
190
+ stub_request(:get, same_origin_uri).to_return(status: 200)
191
+ _(HTTP.send(request_method, uri).success?).must_equal(true)
192
+ end
193
+ end
194
+
195
+ it "keeps a HEAD" do
196
+ stub_request(:head, uri).to_return(status: 303, headers: {'location' => same_origin_uri})
197
+ stub_request(:head, same_origin_uri).to_return(status: 200)
198
+ _(HTTP.head(uri).success?).must_equal(true)
199
+ end
200
+ end
201
+
202
+ %w{307 308}.each do |code|
203
+ describe "via #{code}" do
204
+ it "keeps a POST, with its body" do
205
+ stub_request(:post, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
206
+ stub_request(:post, same_origin_uri).with(body: 'a=1').to_return(status: 200)
207
+ _(HTTP.post(uri, {a: 1}).success?).must_equal(true)
208
+ end
209
+
210
+ it "keeps a method without a named helper" do
211
+ stub_request(:propfind, uri).to_return(status: code.to_i, headers: {'location' => same_origin_uri})
212
+ stub_request(:propfind, same_origin_uri).to_return(status: 207)
213
+ _(HTTP.request_without_body(:propfind, uri).code).must_equal('207')
214
+ end
215
+ end
216
+ end
217
+ end
218
+
219
+ describe "max_redirects" do
220
+ before do
221
+ stub_request(:get, 'http://example.com/0').to_return(status: 302, headers: {'location' => '/1'})
222
+ stub_request(:get, 'http://example.com/1').to_return(status: 302, headers: {'location' => '/2'})
223
+ stub_request(:get, 'http://example.com/2').to_return(status: 200)
224
+ end
225
+
226
+ it "follows as many redirects as it is allowed" do
227
+ _(HTTP.get('http://example.com/0', {}, {}, {max_redirects: 2}).success?).must_equal(true)
228
+ end
229
+
230
+ it "raises TooManyRedirects, with the redirect not followed, when there are more" do
231
+ error = _(->{HTTP.get('http://example.com/0', {}, {}, {max_redirects: 1})}).must_raise(HTTP::TooManyRedirects)
232
+ _(error.response['location']).must_equal('/2')
233
+ assert_not_requested(:get, 'http://example.com/2')
234
+ end
235
+
236
+ it "raises at the first redirect when it is 0" do
237
+ _(->{HTTP.get('http://example.com/0', {}, {}, {max_redirects: 0})}).must_raise(HTTP::TooManyRedirects)
238
+ assert_not_requested(:get, 'http://example.com/1')
239
+ end
240
+
241
+ it "gives way to no_redirect" do
242
+ _(HTTP.get('http://example.com/0', {}, {}, {max_redirects: 0, no_redirect: true}).code).must_equal('302')
243
+ end
244
+
245
+ it "stops a redirect loop at the default" do
246
+ stub_request(:get, uri).to_return(status: 302, headers: {'location' => uri})
247
+ _(->{HTTP.get(uri)}).must_raise(HTTP::TooManyRedirects)
248
+ assert_requested(:get, uri, times: HTTP::REDIRECT::MAX + 1)
249
+ end
250
+
251
+ it "is not passed through to Net::HTTP" do
252
+ stub_request(:get, uri).to_return(status: 200)
253
+ _(HTTP.get(uri, {}, {}, {max_redirects: 5}).success?).must_equal(true)
254
+ end
255
+ end
148
256
  end
@@ -143,7 +143,7 @@ describe ".delete" do
143
143
  let(:redirect_uri){'http://redirected.com'}
144
144
 
145
145
  before do
146
- stub_request(:get, redirect_uri).
146
+ stub_request(:delete, redirect_uri).
147
147
  to_return(status: 200, body: '', headers: {})
148
148
  end
149
149
 
@@ -157,7 +157,7 @@ describe ".delete" do
157
157
  response = HTTP.delete(request_uri)
158
158
  _(response.success?).must_equal(true)
159
159
  assert_requested(:delete, request_uri)
160
- assert_requested(:get, redirect_uri)
160
+ assert_requested(:delete, redirect_uri)
161
161
  end
162
162
  end
163
163
 
@@ -171,7 +171,7 @@ describe ".delete" do
171
171
  response = HTTP.delete(request_uri)
172
172
  _(response.success?).must_equal(true)
173
173
  assert_requested(:delete, request_uri)
174
- assert_requested(:get, redirect_uri)
174
+ assert_requested(:delete, redirect_uri)
175
175
  end
176
176
  end
177
177
  end
@@ -182,7 +182,7 @@ describe ".delete" do
182
182
  let(:redirect_uri){"http://example.com#{redirect_path}"}
183
183
 
184
184
  before do
185
- stub_request(:get, redirect_uri).
185
+ stub_request(:delete, redirect_uri).
186
186
  to_return(status: 200, body: '', headers: {})
187
187
  end
188
188
 
@@ -195,7 +195,7 @@ describe ".delete" do
195
195
  it "resolves the relative redirect against the original URI" do
196
196
  response = HTTP.delete(request_uri)
197
197
  _(response.success?).must_equal(true)
198
- assert_requested(:get, redirect_uri)
198
+ assert_requested(:delete, redirect_uri)
199
199
  end
200
200
  end
201
201
 
@@ -208,7 +208,7 @@ describe ".delete" do
208
208
  it "resolves the relative redirect against the original URI" do
209
209
  response = HTTP.delete(request_uri)
210
210
  _(response.success?).must_equal(true)
211
- assert_requested(:get, redirect_uri)
211
+ assert_requested(:delete, redirect_uri)
212
212
  end
213
213
  end
214
214
  end
@@ -245,7 +245,7 @@ describe ".delete" do
245
245
  it "returns the redirect response without following it" do
246
246
  response = HTTP.delete(request_uri, {}, {}, {no_redirect: true})
247
247
  _(response.redirection?).must_equal(true)
248
- assert_not_requested(:get, redirect_uri)
248
+ assert_not_requested(:delete, redirect_uri)
249
249
  end
250
250
  end
251
251
 
@@ -258,7 +258,7 @@ describe ".delete" do
258
258
  it "returns the redirect response without following it" do
259
259
  response = HTTP.delete(request_uri, {}, {}, {no_redirect: true})
260
260
  _(response.redirection?).must_equal(true)
261
- assert_not_requested(:get, redirect_uri)
261
+ assert_not_requested(:delete, redirect_uri)
262
262
  end
263
263
  end
264
264
  end
@@ -93,7 +93,7 @@ describe ".head" do
93
93
  before do
94
94
  stub_request(:head, request_uri).
95
95
  to_return(status: 301, headers: {'location' => redirect_uri})
96
- stub_request(:get, redirect_uri).
96
+ stub_request(:head, redirect_uri).
97
97
  to_return(status: 200, body: '', headers: {})
98
98
  end
99
99
 
@@ -101,7 +101,7 @@ describe ".head" do
101
101
  response = HTTP.head(request_uri)
102
102
  _(response.success?).must_equal(true)
103
103
  assert_requested(:head, request_uri)
104
- assert_requested(:get, redirect_uri)
104
+ assert_requested(:head, redirect_uri)
105
105
  end
106
106
  end
107
107
 
@@ -143,7 +143,7 @@ describe ".options" do
143
143
  let(:redirect_uri){'http://redirected.com'}
144
144
 
145
145
  before do
146
- stub_request(:get, redirect_uri).
146
+ stub_request(:options, redirect_uri).
147
147
  to_return(status: 200, body: '', headers: {})
148
148
  end
149
149
 
@@ -157,7 +157,7 @@ describe ".options" do
157
157
  response = HTTP.options(request_uri)
158
158
  _(response.success?).must_equal(true)
159
159
  assert_requested(:options, request_uri)
160
- assert_requested(:get, redirect_uri)
160
+ assert_requested(:options, redirect_uri)
161
161
  end
162
162
  end
163
163
 
@@ -171,7 +171,7 @@ describe ".options" do
171
171
  response = HTTP.options(request_uri)
172
172
  _(response.success?).must_equal(true)
173
173
  assert_requested(:options, request_uri)
174
- assert_requested(:get, redirect_uri)
174
+ assert_requested(:options, redirect_uri)
175
175
  end
176
176
  end
177
177
  end
@@ -182,7 +182,7 @@ describe ".options" do
182
182
  let(:redirect_uri){"http://example.com#{redirect_path}"}
183
183
 
184
184
  before do
185
- stub_request(:get, redirect_uri).
185
+ stub_request(:options, redirect_uri).
186
186
  to_return(status: 200, body: '', headers: {})
187
187
  end
188
188
 
@@ -195,7 +195,7 @@ describe ".options" do
195
195
  it "resolves the relative redirect against the original URI" do
196
196
  response = HTTP.options(request_uri)
197
197
  _(response.success?).must_equal(true)
198
- assert_requested(:get, redirect_uri)
198
+ assert_requested(:options, redirect_uri)
199
199
  end
200
200
  end
201
201
 
@@ -208,7 +208,7 @@ describe ".options" do
208
208
  it "resolves the relative redirect against the original URI" do
209
209
  response = HTTP.options(request_uri)
210
210
  _(response.success?).must_equal(true)
211
- assert_requested(:get, redirect_uri)
211
+ assert_requested(:options, redirect_uri)
212
212
  end
213
213
  end
214
214
  end
@@ -226,7 +226,7 @@ describe ".options" do
226
226
  it "returns the redirect response without following it" do
227
227
  response = HTTP.options(request_uri, {}, {}, {no_redirect: true})
228
228
  _(response.redirection?).must_equal(true)
229
- assert_not_requested(:get, redirect_uri)
229
+ assert_not_requested(:options, redirect_uri)
230
230
  end
231
231
  end
232
232
 
@@ -239,7 +239,7 @@ describe ".options" do
239
239
  it "returns the redirect response without following it" do
240
240
  response = HTTP.options(request_uri, {}, {}, {no_redirect: true})
241
241
  _(response.redirection?).must_equal(true)
242
- assert_not_requested(:get, redirect_uri)
242
+ assert_not_requested(:options, redirect_uri)
243
243
  end
244
244
  end
245
245
  end
@@ -286,7 +286,7 @@ describe ".patch" do
286
286
  let(:redirect_uri){'http://redirected.com'}
287
287
 
288
288
  before do
289
- stub_request(:get, redirect_uri).
289
+ stub_request(:patch, redirect_uri).
290
290
  to_return(status: 200, body: '', headers: {})
291
291
  end
292
292
 
@@ -296,11 +296,11 @@ describe ".patch" do
296
296
  to_return(status: 301, headers: {'location' => redirect_uri})
297
297
  end
298
298
 
299
- it "follows the redirect with GET" do
299
+ it "follows the redirect with PATCH" do
300
300
  response = HTTP.patch(request_uri)
301
301
  _(response.success?).must_equal(true)
302
302
  assert_requested(:patch, request_uri)
303
- assert_requested(:get, redirect_uri)
303
+ assert_requested(:patch, redirect_uri)
304
304
  end
305
305
  end
306
306
 
@@ -310,11 +310,11 @@ describe ".patch" do
310
310
  to_return(status: 302, headers: {'location' => redirect_uri})
311
311
  end
312
312
 
313
- it "follows the redirect with GET" do
313
+ it "follows the redirect with PATCH" do
314
314
  response = HTTP.patch(request_uri)
315
315
  _(response.success?).must_equal(true)
316
316
  assert_requested(:patch, request_uri)
317
- assert_requested(:get, redirect_uri)
317
+ assert_requested(:patch, redirect_uri)
318
318
  end
319
319
  end
320
320
  end
@@ -325,7 +325,7 @@ describe ".patch" do
325
325
  let(:redirect_uri){"http://example.com#{redirect_path}"}
326
326
 
327
327
  before do
328
- stub_request(:get, redirect_uri).
328
+ stub_request(:patch, redirect_uri).
329
329
  to_return(status: 200, body: '', headers: {})
330
330
  end
331
331
 
@@ -338,7 +338,7 @@ describe ".patch" do
338
338
  it "resolves the relative redirect against the original URI" do
339
339
  response = HTTP.patch(request_uri)
340
340
  _(response.success?).must_equal(true)
341
- assert_requested(:get, redirect_uri)
341
+ assert_requested(:patch, redirect_uri)
342
342
  end
343
343
  end
344
344
 
@@ -351,7 +351,7 @@ describe ".patch" do
351
351
  it "resolves the relative redirect against the original URI" do
352
352
  response = HTTP.patch(request_uri)
353
353
  _(response.success?).must_equal(true)
354
- assert_requested(:get, redirect_uri)
354
+ assert_requested(:patch, redirect_uri)
355
355
  end
356
356
  end
357
357
  end
@@ -388,7 +388,7 @@ describe ".patch" do
388
388
  it "returns the redirect response without following it" do
389
389
  response = HTTP.patch(request_uri, {}, {}, {no_redirect: true})
390
390
  _(response.redirection?).must_equal(true)
391
- assert_not_requested(:get, redirect_uri)
391
+ assert_not_requested(:patch, redirect_uri)
392
392
  end
393
393
  end
394
394
 
@@ -401,7 +401,7 @@ describe ".patch" do
401
401
  it "returns the redirect response without following it" do
402
402
  response = HTTP.patch(request_uri, {}, {}, {no_redirect: true})
403
403
  _(response.redirection?).must_equal(true)
404
- assert_not_requested(:get, redirect_uri)
404
+ assert_not_requested(:patch, redirect_uri)
405
405
  end
406
406
  end
407
407
  end
@@ -286,7 +286,7 @@ describe ".put" do
286
286
  let(:redirect_uri){'http://redirected.com'}
287
287
 
288
288
  before do
289
- stub_request(:get, redirect_uri).
289
+ stub_request(:put, redirect_uri).
290
290
  to_return(status: 200, body: '', headers: {})
291
291
  end
292
292
 
@@ -296,11 +296,11 @@ describe ".put" do
296
296
  to_return(status: 301, headers: {'location' => redirect_uri})
297
297
  end
298
298
 
299
- it "follows the redirect with GET" do
299
+ it "follows the redirect with PUT" do
300
300
  response = HTTP.put(request_uri)
301
301
  _(response.success?).must_equal(true)
302
302
  assert_requested(:put, request_uri)
303
- assert_requested(:get, redirect_uri)
303
+ assert_requested(:put, redirect_uri)
304
304
  end
305
305
  end
306
306
 
@@ -310,11 +310,11 @@ describe ".put" do
310
310
  to_return(status: 302, headers: {'location' => redirect_uri})
311
311
  end
312
312
 
313
- it "follows the redirect with GET" do
313
+ it "follows the redirect with PUT" do
314
314
  response = HTTP.put(request_uri)
315
315
  _(response.success?).must_equal(true)
316
316
  assert_requested(:put, request_uri)
317
- assert_requested(:get, redirect_uri)
317
+ assert_requested(:put, redirect_uri)
318
318
  end
319
319
  end
320
320
  end
@@ -325,7 +325,7 @@ describe ".put" do
325
325
  let(:redirect_uri){"http://example.com#{redirect_path}"}
326
326
 
327
327
  before do
328
- stub_request(:get, redirect_uri).
328
+ stub_request(:put, redirect_uri).
329
329
  to_return(status: 200, body: '', headers: {})
330
330
  end
331
331
 
@@ -338,7 +338,7 @@ describe ".put" do
338
338
  it "resolves the relative redirect against the original URI" do
339
339
  response = HTTP.put(request_uri)
340
340
  _(response.success?).must_equal(true)
341
- assert_requested(:get, redirect_uri)
341
+ assert_requested(:put, redirect_uri)
342
342
  end
343
343
  end
344
344
 
@@ -351,7 +351,7 @@ describe ".put" do
351
351
  it "resolves the relative redirect against the original URI" do
352
352
  response = HTTP.put(request_uri)
353
353
  _(response.success?).must_equal(true)
354
- assert_requested(:get, redirect_uri)
354
+ assert_requested(:put, redirect_uri)
355
355
  end
356
356
  end
357
357
  end
@@ -388,7 +388,7 @@ describe ".put" do
388
388
  it "returns the redirect response without following it" do
389
389
  response = HTTP.put(request_uri, {}, {}, {no_redirect: true})
390
390
  _(response.redirection?).must_equal(true)
391
- assert_not_requested(:get, redirect_uri)
391
+ assert_not_requested(:put, redirect_uri)
392
392
  end
393
393
  end
394
394
 
@@ -401,7 +401,7 @@ describe ".put" do
401
401
  it "returns the redirect response without following it" do
402
402
  response = HTTP.put(request_uri, {}, {}, {no_redirect: true})
403
403
  _(response.redirection?).must_equal(true)
404
- assert_not_requested(:get, redirect_uri)
404
+ assert_not_requested(:put, redirect_uri)
405
405
  end
406
406
  end
407
407
  end
@@ -143,7 +143,7 @@ describe ".trace" do
143
143
  let(:redirect_uri){'http://redirected.com'}
144
144
 
145
145
  before do
146
- stub_request(:get, redirect_uri).
146
+ stub_request(:trace, redirect_uri).
147
147
  to_return(status: 200, body: '', headers: {})
148
148
  end
149
149
 
@@ -157,7 +157,7 @@ describe ".trace" do
157
157
  response = HTTP.trace(request_uri)
158
158
  _(response.success?).must_equal(true)
159
159
  assert_requested(:trace, request_uri)
160
- assert_requested(:get, redirect_uri)
160
+ assert_requested(:trace, redirect_uri)
161
161
  end
162
162
  end
163
163
 
@@ -171,7 +171,7 @@ describe ".trace" do
171
171
  response = HTTP.trace(request_uri)
172
172
  _(response.success?).must_equal(true)
173
173
  assert_requested(:trace, request_uri)
174
- assert_requested(:get, redirect_uri)
174
+ assert_requested(:trace, redirect_uri)
175
175
  end
176
176
  end
177
177
  end
@@ -182,7 +182,7 @@ describe ".trace" do
182
182
  let(:redirect_uri){"http://example.com#{redirect_path}"}
183
183
 
184
184
  before do
185
- stub_request(:get, redirect_uri).
185
+ stub_request(:trace, redirect_uri).
186
186
  to_return(status: 200, body: '', headers: {})
187
187
  end
188
188
 
@@ -195,7 +195,7 @@ describe ".trace" do
195
195
  it "resolves the relative redirect against the original URI" do
196
196
  response = HTTP.trace(request_uri)
197
197
  _(response.success?).must_equal(true)
198
- assert_requested(:get, redirect_uri)
198
+ assert_requested(:trace, redirect_uri)
199
199
  end
200
200
  end
201
201
 
@@ -208,7 +208,7 @@ describe ".trace" do
208
208
  it "resolves the relative redirect against the original URI" do
209
209
  response = HTTP.trace(request_uri)
210
210
  _(response.success?).must_equal(true)
211
- assert_requested(:get, redirect_uri)
211
+ assert_requested(:trace, redirect_uri)
212
212
  end
213
213
  end
214
214
  end
@@ -226,7 +226,7 @@ describe ".trace" do
226
226
  it "returns the redirect response without following it" do
227
227
  response = HTTP.trace(request_uri, {}, {}, {no_redirect: true})
228
228
  _(response.redirection?).must_equal(true)
229
- assert_not_requested(:get, redirect_uri)
229
+ assert_not_requested(:trace, redirect_uri)
230
230
  end
231
231
  end
232
232
 
@@ -239,7 +239,7 @@ describe ".trace" do
239
239
  it "returns the redirect response without following it" do
240
240
  response = HTTP.trace(request_uri, {}, {}, {no_redirect: true})
241
241
  _(response.redirection?).must_equal(true)
242
- assert_not_requested(:get, redirect_uri)
242
+ assert_not_requested(:trace, redirect_uri)
243
243
  end
244
244
  end
245
245
  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.3.11
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran