http.rb 0.21.0 → 0.22.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.
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: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -10,7 +10,21 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: pry
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '6.0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '6.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest-mock
14
28
  requirement: !ruby/object:Gem::Requirement
15
29
  requirements:
16
30
  - - ">="
@@ -24,7 +38,7 @@ dependencies:
24
38
  - !ruby/object:Gem::Version
25
39
  version: '0'
26
40
  - !ruby/object:Gem::Dependency
27
- name: rake
41
+ name: pry
28
42
  requirement: !ruby/object:Gem::Requirement
29
43
  requirements:
30
44
  - - ">="
@@ -38,7 +52,7 @@ dependencies:
38
52
  - !ruby/object:Gem::Version
39
53
  version: '0'
40
54
  - !ruby/object:Gem::Dependency
41
- name: rspec
55
+ name: rake
42
56
  requirement: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - ">="
@@ -94,16 +108,16 @@ files:
94
108
  - lib/Thoran/Array/FirstX/firstX.rb
95
109
  - lib/Thoran/String/ToConst/to_const.rb
96
110
  - lib/URI/Generic/use_sslQ.rb
97
- - spec/HTTP/RETRY_spec.rb
98
- - spec/HTTP/delete_spec.rb
99
- - spec/HTTP/get_spec.rb
100
- - spec/HTTP/head_spec.rb
101
- - spec/HTTP/options_spec.rb
102
- - spec/HTTP/patch_spec.rb
103
- - spec/HTTP/post_spec.rb
104
- - spec/HTTP/put_spec.rb
105
- - spec/HTTP/trace_spec.rb
106
- - spec/spec_helper.rb
111
+ - test/HTTP/RETRY_test.rb
112
+ - test/HTTP/delete_test.rb
113
+ - test/HTTP/get_test.rb
114
+ - test/HTTP/head_test.rb
115
+ - test/HTTP/options_test.rb
116
+ - test/HTTP/patch_test.rb
117
+ - test/HTTP/post_test.rb
118
+ - test/HTTP/put_test.rb
119
+ - test/HTTP/trace_test.rb
120
+ - test/helper.rb
107
121
  homepage: http://github.com/thoran/HTTP
108
122
  licenses:
109
123
  - MIT
@@ -1,251 +0,0 @@
1
- # spec/HTTP/RETRY_spec.rb
2
-
3
- require_relative '../spec_helper'
4
- require 'http'
5
-
6
- describe "retry behaviour" do
7
- let(:uri){'http://example.com/path'}
8
-
9
- before do
10
- allow(HTTP::RETRY).to receive(:sleep)
11
- end
12
-
13
- describe "defaults" do
14
- it "does not retry by default" do
15
- stub_request(:get, uri).to_return(status: 503)
16
- response = HTTP.get(uri)
17
- expect(response.code.to_i).to eq(503)
18
- expect(WebMock).to have_requested(:get, uri).times(1)
19
- end
20
-
21
- it "does not retry on a transient exception by default" do
22
- stub_request(:get, uri).to_raise(Errno::ECONNRESET)
23
- expect{HTTP.get(uri)}.to raise_error(Errno::ECONNRESET)
24
- expect(WebMock).to have_requested(:get, uri).times(1)
25
- end
26
- end
27
-
28
- describe "retry on transient exception" do
29
- it "retries and succeeds when the failure is transient" do
30
- stub_request(:get, uri).
31
- to_raise(Errno::ECONNRESET).then.
32
- to_raise(Errno::ECONNRESET).then.
33
- to_return(status: 200, body: '')
34
- response = HTTP.get(uri, {}, {}, {retries: 3})
35
- expect(response.success?).to eq(true)
36
- expect(WebMock).to have_requested(:get, uri).times(3)
37
- end
38
-
39
- it "re-raises the exception after retries are exhausted" do
40
- stub_request(:get, uri).to_raise(Errno::ECONNRESET)
41
- expect{HTTP.get(uri, {}, {}, {retries: 2})}.to raise_error(Errno::ECONNRESET)
42
- expect(WebMock).to have_requested(:get, uri).times(3)
43
- end
44
-
45
- it "retries on SocketError (DNS failure)" do
46
- stub_request(:get, uri).
47
- to_raise(SocketError).then.
48
- to_return(status: 200, body: '')
49
- response = HTTP.get(uri, {}, {}, {retries: 3})
50
- expect(response.success?).to eq(true)
51
- expect(WebMock).to have_requested(:get, uri).times(2)
52
- end
53
-
54
- it "does not retry on a non-listed exception" do
55
- stub_request(:get, uri).to_raise(OpenSSL::SSL::SSLError)
56
- expect{HTTP.get(uri, {}, {}, {retries: 3})}.to raise_error(OpenSSL::SSL::SSLError)
57
- expect(WebMock).to have_requested(:get, uri).times(1)
58
- end
59
- end
60
-
61
- describe "retry on status code" do
62
- it "retries on 503 then succeeds" do
63
- stub_request(:get, uri).
64
- to_return({status: 503}, {status: 503}, {status: 200, body: ''})
65
- response = HTTP.get(uri, {}, {}, {retries: 3})
66
- expect(response.success?).to eq(true)
67
- expect(WebMock).to have_requested(:get, uri).times(3)
68
- end
69
-
70
- it "retries on 502" do
71
- stub_request(:get, uri).to_return({status: 502}, {status: 200, body: ''})
72
- response = HTTP.get(uri, {}, {}, {retries: 3})
73
- expect(response.success?).to eq(true)
74
- expect(WebMock).to have_requested(:get, uri).times(2)
75
- end
76
-
77
- it "retries on 504" do
78
- stub_request(:get, uri).to_return({status: 504}, {status: 200, body: ''})
79
- response = HTTP.get(uri, {}, {}, {retries: 3})
80
- expect(response.success?).to eq(true)
81
- expect(WebMock).to have_requested(:get, uri).times(2)
82
- end
83
-
84
- it "does not retry on 500 by default" do
85
- stub_request(:get, uri).to_return(status: 500)
86
- response = HTTP.get(uri, {}, {}, {retries: 3})
87
- expect(response.code.to_i).to eq(500)
88
- expect(WebMock).to have_requested(:get, uri).times(1)
89
- end
90
-
91
- it "does not retry on 404" do
92
- stub_request(:get, uri).to_return(status: 404)
93
- response = HTTP.get(uri, {}, {}, {retries: 3})
94
- expect(response.code.to_i).to eq(404)
95
- expect(WebMock).to have_requested(:get, uri).times(1)
96
- end
97
-
98
- it "returns the last response when retries are exhausted" do
99
- stub_request(:get, uri).to_return(status: 503)
100
- response = HTTP.get(uri, {}, {}, {retries: 2})
101
- expect(response.code.to_i).to eq(503)
102
- expect(WebMock).to have_requested(:get, uri).times(3)
103
- end
104
- end
105
-
106
- describe "Retry-After header" do
107
- it "honours integer Retry-After on 429" do
108
- stub_request(:get, uri).
109
- to_return({status: 429, headers: {'Retry-After' => '2'}}, {status: 200, body: ''})
110
- expect(HTTP::RETRY).to receive(:sleep).with(2)
111
- response = HTTP.get(uri, {}, {}, {retries: 3})
112
- expect(response.success?).to eq(true)
113
- end
114
-
115
- it "honours integer Retry-After on 503" do
116
- stub_request(:get, uri).
117
- to_return({status: 503, headers: {'Retry-After' => '5'}}, {status: 200, body: ''})
118
- expect(HTTP::RETRY).to receive(:sleep).with(5)
119
- response = HTTP.get(uri, {}, {}, {retries: 3})
120
- expect(response.success?).to eq(true)
121
- end
122
- end
123
-
124
- describe "configuration" do
125
- it "treats retries: 0 as no retries" do
126
- stub_request(:get, uri).to_return(status: 503)
127
- response = HTTP.get(uri, {}, {}, {retries: 0})
128
- expect(response.code.to_i).to eq(503)
129
- expect(WebMock).to have_requested(:get, uri).times(1)
130
- end
131
-
132
- it "respects a custom retry_status_codes list" do
133
- stub_request(:get, uri).to_return({status: 500}, {status: 200, body: ''})
134
- response = HTTP.get(uri, {}, {}, {retries: 3, retry_status_codes: [500]})
135
- expect(response.success?).to eq(true)
136
- expect(WebMock).to have_requested(:get, uri).times(2)
137
- end
138
-
139
- it "respects a custom retry_exceptions list" do
140
- stub_request(:get, uri).
141
- to_raise(OpenSSL::SSL::SSLError).then.
142
- to_return(status: 200, body: '')
143
- response = HTTP.get(uri, {}, {}, {retries: 3, retry_exceptions: [OpenSSL::SSL::SSLError]})
144
- expect(response.success?).to eq(true)
145
- expect(WebMock).to have_requested(:get, uri).times(2)
146
- end
147
-
148
- it "does not pass retry options through to Net::HTTP" do
149
- stub_request(:get, uri).to_return(status: 200, body: '')
150
- net_http_object = Net::HTTP.new(URI.parse(uri).host, URI.parse(uri).port)
151
- allow(Net::HTTP).to receive(:new).and_return(net_http_object)
152
- expect(net_http_object).to receive(:options=) do |opts|
153
- expect(opts).not_to include(:retries, :retry_delay, :retry_status_codes, :retry_exceptions, :retry_verbs)
154
- end
155
- HTTP.get(uri, {}, {}, {
156
- retries: 3,
157
- retry_delay: 0.1,
158
- retry_status_codes: [500],
159
- retry_exceptions: [Errno::ECONNRESET],
160
- retry_verbs: %i{get}
161
- })
162
- end
163
- end
164
-
165
- describe "backoff timing" do
166
- it "increases the delay between successive retries" do
167
- delays = []
168
- allow(HTTP::RETRY).to receive(:sleep){|d| delays << d}
169
- stub_request(:get, uri).to_return(status: 503)
170
- HTTP.get(uri, {}, {}, {retries: 3, retry_delay: 1.0})
171
- expect(delays.length).to eq(3)
172
- expect(delays[1]).to be > delays[0] * 0.8
173
- expect(delays[2]).to be > delays[1] * 0.8
174
- end
175
- end
176
-
177
- describe "verb-based retry default" do
178
- it "does not retry POST by default even when retries are enabled" do
179
- stub_request(:post, uri).to_return(status: 503)
180
- HTTP.post(uri, {}, {}, {retries: 3})
181
- expect(WebMock).to have_requested(:post, uri).times(1)
182
- end
183
-
184
- it "does not retry PATCH by default" do
185
- stub_request(:patch, uri).to_return(status: 503)
186
- HTTP.patch(uri, {}, {}, {retries: 3})
187
- expect(WebMock).to have_requested(:patch, uri).times(1)
188
- end
189
-
190
- it "retries PUT by default (idempotent)" do
191
- stub_request(:put, uri).to_return({status: 503}, {status: 200, body: ''})
192
- response = HTTP.put(uri, {}, {}, {retries: 3})
193
- expect(response.success?).to eq(true)
194
- expect(WebMock).to have_requested(:put, uri).times(2)
195
- end
196
-
197
- it "retries DELETE by default (idempotent)" do
198
- stub_request(:delete, uri).to_return({status: 503}, {status: 200, body: ''})
199
- response = HTTP.delete(uri, {}, {}, {retries: 3})
200
- expect(response.success?).to eq(true)
201
- expect(WebMock).to have_requested(:delete, uri).times(2)
202
- end
203
-
204
- it "retries POST when opted in via retry_verbs" do
205
- stub_request(:post, uri).to_return({status: 503}, {status: 200, body: ''})
206
- response = HTTP.post(uri, {}, {}, {retries: 3, retry_verbs: %i{get post}})
207
- expect(response.success?).to eq(true)
208
- expect(WebMock).to have_requested(:post, uri).times(2)
209
- end
210
- end
211
- end
212
-
213
- describe HTTP, ".retry_after" do
214
- it "returns integer seconds for a delta-seconds Retry-After header" do
215
- response = instance_double(Net::HTTPResponse)
216
- allow(response).to receive(:[]).with('Retry-After').and_return('5')
217
- expect(HTTP.retry_after(response)).to eq(5)
218
- end
219
-
220
- it "parses an HTTP-date Retry-After header" do
221
- base = Time.utc(2026, 5, 22, 12, 0, 0)
222
- retry_at_header = (base + 5).httpdate
223
- response = instance_double(Net::HTTPResponse)
224
- allow(response).to receive(:[]).with('Retry-After').and_return(retry_at_header)
225
- allow(Time).to receive(:now).and_return(base)
226
- expect(HTTP.retry_after(response)).to be_within(0.001).of(5.0)
227
- end
228
-
229
- it "returns nil when Retry-After is absent" do
230
- response = instance_double(Net::HTTPResponse)
231
- allow(response).to receive(:[]).with('Retry-After').and_return(nil)
232
- expect(HTTP.retry_after(response)).to be_nil
233
- end
234
-
235
- it "returns nil when Retry-After is malformed" do
236
- response = instance_double(Net::HTTPResponse)
237
- allow(response).to receive(:[]).with('Retry-After').and_return('not a date')
238
- expect(HTTP.retry_after(response)).to be_nil
239
- end
240
- end
241
-
242
- describe HTTP, ".backoff_delay" do
243
- it "grows exponentially with attempt number" do
244
- base = 1.0
245
- delays = (1..4).map{|attempt| HTTP.backoff_delay(base, attempt)}
246
- expect(delays[0]).to be_within(0.2).of(1.0)
247
- expect(delays[1]).to be_within(0.4).of(2.0)
248
- expect(delays[2]).to be_within(0.8).of(4.0)
249
- expect(delays[3]).to be_within(1.6).of(8.0)
250
- end
251
- end
@@ -1,268 +0,0 @@
1
- # spec/HTTP/delete_spec.rb
2
-
3
- require_relative '../spec_helper'
4
- require 'http'
5
-
6
- describe ".delete" do
7
- context "with uri-only supplied" do
8
- before do
9
- stub_request(:delete, 'http://example.com/path').
10
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
11
- to_return(status: 200, body: '', headers: {})
12
- end
13
-
14
- context "uri as a string" do
15
- let(:uri){'http://example.com/path'}
16
- let(:parsed_uri){URI.parse(uri)}
17
- let(:net_http_object){Net::HTTP.new(parsed_uri.host, parsed_uri.port)}
18
-
19
- it "creates an instance of URI" do
20
- expect(URI).to receive(:parse).with(uri).and_return(parsed_uri)
21
- response = HTTP.delete(uri)
22
- expect(response.success?).to eq(true)
23
- end
24
-
25
- it "creates a new Net::HTTP object" do
26
- expect(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
27
- response = HTTP.delete(uri)
28
- expect(response.success?).to eq(true)
29
- end
30
- end
31
-
32
- context "uri as a URI" do
33
- let(:uri_string){'http://example.com/path'}
34
- let(:uri){URI.parse(uri_string)}
35
- let(:net_http_object){Net::HTTP.new(uri.host, uri.port)}
36
-
37
- it "returns an instance of URI" do
38
- expect(uri).to eq(uri)
39
- HTTP.delete(uri)
40
- end
41
-
42
- it "creates a new Net::HTTP object" do
43
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_return(net_http_object)
44
- response = HTTP.delete(uri)
45
- expect(response.success?).to eq(true)
46
- end
47
- end
48
- end
49
-
50
- context "with args supplied" do
51
- let(:uri){'http://example.com/path'}
52
- let(:parsed_uri){URI.parse(uri)}
53
- let(:args) do; {a: 1, b: 2}; end
54
- let(:x_www_form_urlencoded_arguments) do; args.x_www_form_urlencode; end
55
- let(:get_argument){parsed_uri.request_uri + '?' + x_www_form_urlencoded_arguments}
56
- let(:request_object){Net::HTTP::Delete.new(get_argument)}
57
-
58
- before do
59
- stub_request(:delete, 'http://example.com/path?a=1&b=2').
60
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
61
- to_return(status: 200, body: '', headers: {})
62
- end
63
-
64
- it "x_www_form_urlencode's the args" do
65
- expect(args).to receive(:x_www_form_urlencode).and_return(x_www_form_urlencoded_arguments)
66
- response = HTTP.delete(uri, args)
67
- expect(response.success?).to eq(true)
68
- end
69
-
70
- it "creates a new Net::HTTP::Delete object" do
71
- expect(Net::HTTP::Delete).to receive(:new).with(get_argument).and_return(request_object)
72
- response = HTTP.delete(uri, args)
73
- expect(response.success?).to eq(true)
74
- end
75
- end
76
-
77
- context "with headers supplied" do
78
- let(:uri){'http://example.com/path'}
79
- let(:parsed_uri){URI.parse(uri)}
80
- let(:headers) do; {'User-Agent' => 'Rspec'}; end
81
- let(:get_argument){parsed_uri.request_uri}
82
- let(:request_object){Net::HTTP::Delete.new(get_argument)}
83
-
84
- before do
85
- stub_request(:delete, 'http://example.com/path').
86
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Rspec'}).
87
- to_return(status: 200, body: '', headers: {})
88
- end
89
-
90
- it "sets the headers on the request object" do
91
- allow(Net::HTTP::Delete).to receive(:new).with(get_argument).and_return(request_object)
92
- response = HTTP.delete(uri, {}, headers)
93
- expect(request_object['User-Agent']).to eq('Rspec')
94
- expect(response.success?).to eq(true)
95
- end
96
- end
97
-
98
- context "with options supplied" do
99
- let(:uri){'http://example.com/path'}
100
- let(:parsed_uri){URI.parse(uri)}
101
- let(:net_http_object){Net::HTTP.new(parsed_uri.host, parsed_uri.port)}
102
- let(:options) do; {use_ssl: true}; end
103
-
104
- before do
105
- stub_request(:delete, 'https://example.com:80/path').
106
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
107
- to_return(status: 200, body: '', headers: {})
108
- end
109
-
110
- it "sets the use_ssl option on the Net::HTTP instance" do
111
- allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
112
- response = HTTP.delete(uri, {}, {}, options)
113
- expect(net_http_object.instance_variable_get(:@use_ssl)).to be_truthy
114
- expect(response.success?).to eq(true)
115
- end
116
- end
117
-
118
- context "with block supplied" do
119
- let(:uri){'http://example.com/path'}
120
-
121
- before do
122
- stub_request(:delete, 'http://example.com/path').
123
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
124
- to_return(status: 200, body: '', headers: {})
125
- end
126
-
127
- it "yields an instance of Net::HTTPResponse" do
128
- expect{|b| HTTP.delete(uri, &b)}.to yield_with_args(Net::HTTPResponse)
129
- end
130
- end
131
-
132
- context "with redirection" do
133
- let(:request_uri){'http://example.com/path'}
134
- let(:redirect_uri){'http://redirected.com'}
135
-
136
- before do
137
- stub_request(:get, redirect_uri).
138
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
139
- to_return(status: 200, body: '', headers: {})
140
- end
141
-
142
- context "via 301" do
143
- before do
144
- stub_request(:delete, request_uri).
145
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
146
- to_return(status: 301, body: '', headers: {'location' => redirect_uri})
147
- end
148
-
149
- it "does a redirect" do
150
- expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
151
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
152
- response = HTTP.delete(request_uri)
153
- expect(response.success?).to eq(true)
154
- end
155
- end
156
-
157
- context "via 302" do
158
- before do
159
- stub_request(:delete, request_uri).
160
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
161
- to_return(status: 302, body: '', headers: {'location' => redirect_uri})
162
- end
163
-
164
- it "does a redirect" do
165
- expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
166
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
167
- response = HTTP.delete(request_uri)
168
- expect(response.success?).to eq(true)
169
- end
170
- end
171
- end
172
-
173
- context "with path only redirection" do
174
- let(:request_uri){'http://example.com/path'}
175
- let(:redirect_path){'/new_path'}
176
- let(:redirect_uri){"http://example.com#{redirect_path}"}
177
-
178
- before do
179
- stub_request(:get, redirect_uri).
180
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
181
- to_return(status: 200, body: '', headers: {})
182
- end
183
-
184
- context "via 301" do
185
- before do
186
- stub_request(:delete, request_uri).
187
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
188
- to_return(status: 301, body: '', headers: {'location' => redirect_path})
189
- end
190
-
191
- it "does a redirect" do
192
- expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
193
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
194
- response = HTTP.delete(request_uri)
195
- expect(response.success?).to eq(true)
196
- end
197
- end
198
-
199
- context "via 302" do
200
- before do
201
- stub_request(:delete, request_uri).
202
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
203
- to_return(status: 302, body: '', headers: {'location' => redirect_path})
204
- end
205
-
206
- it "does a redirect" do
207
- expect(HTTP).to receive(:delete).once.with(request_uri).and_call_original
208
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
209
- response = HTTP.delete(request_uri)
210
- expect(response.success?).to eq(true)
211
- end
212
- end
213
- end
214
-
215
- context "with verb-preserving redirection via 307" do
216
- let(:request_uri){'http://example.com/path'}
217
- let(:redirect_uri){'http://redirected.com'}
218
-
219
- before do
220
- stub_request(:delete, request_uri).
221
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
222
- to_return(status: 307, body: '', headers: {'location' => redirect_uri})
223
- stub_request(:delete, redirect_uri).
224
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
225
- to_return(status: 200, body: '', headers: {})
226
- end
227
-
228
- it "preserves the verb" do
229
- expect(HTTP).to receive(:delete).with(request_uri).and_call_original.ordered
230
- expect(HTTP).to receive(:delete).with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original.ordered
231
- response = HTTP.delete(request_uri)
232
- expect(response.success?).to eq(true)
233
- end
234
- end
235
-
236
- context "no_redirect true" do
237
- let(:request_uri){'http://example.com/path'}
238
- let(:redirect_uri){'http://redirected.com'}
239
-
240
- context "via 301" do
241
- before do
242
- stub_request(:delete, request_uri).
243
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
244
- to_return(status: 301, body: '', headers: {'location' => redirect_uri})
245
- end
246
-
247
- it "doesn't redirect" do
248
- expect(HTTP).to receive(:delete).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
249
- response = HTTP.delete(request_uri, {}, {}, {no_redirect: true})
250
- expect(response.redirection?).to eq(true)
251
- end
252
- end
253
-
254
- context "via 302" do
255
- before do
256
- stub_request(:delete, request_uri).
257
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
258
- to_return(status: 302, body: '', headers: {'location' => redirect_uri})
259
- end
260
-
261
- it "doesn't redirect" do
262
- expect(HTTP).to receive(:delete).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
263
- response = HTTP.delete(request_uri, {}, {}, {no_redirect: true})
264
- expect(response.redirection?).to eq(true)
265
- end
266
- end
267
- end
268
- end