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.
@@ -1,295 +0,0 @@
1
- # spec/HTTP/get_spec.rb
2
-
3
- require_relative '../spec_helper'
4
- require 'http'
5
-
6
- describe ".get" do
7
- context "with uri-only supplied" do
8
- before do
9
- stub_request(:get, '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.get(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.get(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.get(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.get(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::Get.new(get_argument)}
57
-
58
- before do
59
- stub_request(:get, '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.get(uri, args)
67
- expect(response.success?).to eq(true)
68
- end
69
-
70
- it "creates a new Net::HTTP::Get object" do
71
- expect(Net::HTTP::Get).to receive(:new).with(get_argument).and_return(request_object)
72
- response = HTTP.get(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::Get.new(get_argument)}
83
-
84
- before do
85
- stub_request(:get, '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::Get).to receive(:new).with(get_argument).and_return(request_object)
92
- response = HTTP.get(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(:get, '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.get(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 default verify_mode" do
119
- let(:uri){'http://example.com/path'}
120
- let(:parsed_uri){URI.parse(uri)}
121
- let(:net_http_object){Net::HTTP.new(parsed_uri.host, parsed_uri.port)}
122
-
123
- before do
124
- stub_request(:get, uri).
125
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
126
- to_return(status: 200, body: '', headers: {})
127
- end
128
-
129
- it "defaults verify_mode to OpenSSL::SSL::VERIFY_PEER" do
130
- allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
131
- response = HTTP.get(uri)
132
- expect(net_http_object.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
133
- expect(response.success?).to eq(true)
134
- end
135
-
136
- it "allows opting back into VERIFY_NONE via options" do
137
- allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
138
- response = HTTP.get(uri, {}, {}, {verify_mode: OpenSSL::SSL::VERIFY_NONE})
139
- expect(net_http_object.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
140
- expect(response.success?).to eq(true)
141
- end
142
- end
143
-
144
- context "with block supplied" do
145
- let(:uri){'http://example.com/path'}
146
-
147
- before do
148
- stub_request(:get, 'http://example.com/path').
149
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
150
- to_return(status: 200, body: '', headers: {})
151
- end
152
-
153
- it "yields an instance of Net::HTTPResponse" do
154
- expect{|b| HTTP.get(uri, &b)}.to yield_with_args(Net::HTTPResponse)
155
- end
156
- end
157
-
158
- context "with redirection" do
159
- let(:request_uri){'http://example.com/path'}
160
- let(:redirect_uri){'http://redirected.com'}
161
-
162
- before do
163
- stub_request(:get, redirect_uri).
164
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
165
- to_return(status: 200, body: '', headers: {})
166
- end
167
-
168
- context "via 301" do
169
- before do
170
- stub_request(:get, request_uri).
171
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
172
- to_return(status: 301, body: '', headers: {'location' => redirect_uri})
173
- end
174
-
175
- it "does a redirect" do
176
- expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
177
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
178
- response = HTTP.get(request_uri)
179
- expect(response.success?).to eq(true)
180
- end
181
- end
182
-
183
- context "via 302" do
184
- before do
185
- stub_request(:get, request_uri).
186
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
187
- to_return(status: 302, body: '', headers: {'location' => redirect_uri})
188
- end
189
-
190
- it "does a redirect" do
191
- expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
192
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
193
- response = HTTP.get(request_uri)
194
- expect(response.success?).to eq(true)
195
- end
196
- end
197
- end
198
-
199
- context "with path only redirection" do
200
- let(:request_uri){'http://example.com/path'}
201
- let(:redirect_path){'/new_path'}
202
- let(:redirect_uri){"http://example.com#{redirect_path}"}
203
-
204
- before do
205
- stub_request(:get, redirect_uri).
206
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
207
- to_return(status: 200, body: '', headers: {})
208
- end
209
-
210
- context "via 301" do
211
- before do
212
- stub_request(:get, request_uri).
213
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
214
- to_return(status: 301, body: '', headers: {'location' => redirect_path})
215
- end
216
-
217
- it "does a redirect" do
218
- expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
219
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
220
- response = HTTP.get(request_uri)
221
- expect(response.success?).to eq(true)
222
- end
223
- end
224
-
225
- context "via 302" do
226
- before do
227
- stub_request(:get, request_uri).
228
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
229
- to_return(status: 302, body: '', headers: {'location' => redirect_path})
230
- end
231
-
232
- it "does a redirect" do
233
- expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
234
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
235
- response = HTTP.get(request_uri)
236
- expect(response.success?).to eq(true)
237
- end
238
- end
239
- end
240
-
241
- context "with path only redirection from HTTPS" do
242
- let(:request_uri){'https://example.com/path'}
243
- let(:redirect_path){'/new_path'}
244
- let(:redirect_uri){"https://example.com#{redirect_path}"}
245
-
246
- before do
247
- stub_request(:get, redirect_uri).
248
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
249
- to_return(status: 200, body: '', headers: {})
250
- stub_request(:get, request_uri).
251
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
252
- to_return(status: 301, body: '', headers: {'location' => redirect_path})
253
- end
254
-
255
- it "preserves the HTTPS scheme on a relative redirect" do
256
- expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
257
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_PEER}).and_call_original
258
- response = HTTP.get(request_uri)
259
- expect(response.success?).to eq(true)
260
- end
261
- end
262
-
263
- context "no_redirect true" do
264
- let(:request_uri){'http://example.com/path'}
265
- let(:redirect_uri){'http://redirected.com'}
266
-
267
- context "via 301" do
268
- before do
269
- stub_request(:get, request_uri).
270
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
271
- to_return(status: 301, body: '', headers: {'location' => redirect_uri})
272
- end
273
-
274
- it "doesn't redirect" do
275
- expect(HTTP).to receive(:get).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
276
- response = HTTP.get(request_uri, {}, {}, {no_redirect: true})
277
- expect(response.redirection?).to eq(true)
278
- end
279
- end
280
-
281
- context "via 302" do
282
- before do
283
- stub_request(:get, request_uri).
284
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
285
- to_return(status: 302, body: '', headers: {'location' => redirect_uri})
286
- end
287
-
288
- it "doesn't redirect" do
289
- expect(HTTP).to receive(:get).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
290
- response = HTTP.get(request_uri, {}, {}, {no_redirect: true})
291
- expect(response.redirection?).to eq(true)
292
- end
293
- end
294
- end
295
- end
@@ -1,247 +0,0 @@
1
- # spec/HTTP/options_spec.rb
2
-
3
- require_relative '../spec_helper'
4
- require 'http'
5
-
6
- describe ".options" do
7
- context "with uri-only supplied" do
8
- before do
9
- stub_request(:options, '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.options(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.options(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.options(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.options(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(:options_argument){parsed_uri.request_uri + '?' + x_www_form_urlencoded_arguments}
56
- let(:request_object){Net::HTTP::Options.new(options_argument)}
57
-
58
- before do
59
- stub_request(:options, '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.options(uri, args)
67
- expect(response.success?).to eq(true)
68
- end
69
-
70
- it "creates a new Net::HTTP::Options object" do
71
- expect(Net::HTTP::Options).to receive(:new).with(options_argument).and_return(request_object)
72
- response = HTTP.options(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(:options_argument){parsed_uri.request_uri}
82
- let(:request_object){Net::HTTP::Options.new(options_argument)}
83
-
84
- before do
85
- stub_request(:options, '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::Options).to receive(:new).with(options_argument).and_return(request_object)
92
- response = HTTP.options(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(:options, '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.options(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(:options, '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.options(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(:options, 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(:options).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.options(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(:options, 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(:options).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.options(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(:options, 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(:options).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.options(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(:options, 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(:options).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.options(request_uri)
210
- expect(response.success?).to eq(true)
211
- end
212
- end
213
- end
214
-
215
- context "no_redirect true" do
216
- let(:request_uri){'http://example.com/path'}
217
- let(:redirect_uri){'http://redirected.com'}
218
-
219
- context "via 301" do
220
- before do
221
- stub_request(:options, request_uri).
222
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
223
- to_return(status: 301, body: '', headers: {'location' => redirect_uri})
224
- end
225
-
226
- it "doesn't redirect" do
227
- expect(HTTP).to receive(:options).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
228
- response = HTTP.options(request_uri, {}, {}, {no_redirect: true})
229
- expect(response.redirection?).to eq(true)
230
- end
231
- end
232
-
233
- context "via 302" do
234
- before do
235
- stub_request(:options, request_uri).
236
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
237
- to_return(status: 302, body: '', headers: {'location' => redirect_uri})
238
- end
239
-
240
- it "doesn't redirect" do
241
- expect(HTTP).to receive(:options).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
242
- response = HTTP.options(request_uri, {}, {}, {no_redirect: true})
243
- expect(response.redirection?).to eq(true)
244
- end
245
- end
246
- end
247
- end