faraday 2.0.0.alpha.pre.4 → 2.2.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.md +77 -3
- data/README.md +0 -5
- data/examples/client_spec.rb +19 -19
- data/examples/client_test.rb +22 -22
- data/lib/faraday/adapter/test.rb +8 -4
- data/lib/faraday/connection.rb +8 -8
- data/lib/faraday/error.rb +2 -8
- data/lib/faraday/middleware_registry.rb +19 -1
- data/lib/faraday/rack_builder.rb +23 -20
- data/lib/faraday/request.rb +0 -2
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +7 -4
- data/spec/faraday/connection_spec.rb +38 -35
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/rack_builder_spec.rb +29 -19
- data/spec/faraday/request/url_encoded_spec.rb +0 -1
- data/spec/faraday/request_spec.rb +4 -4
- data/spec/faraday/utils/headers_spec.rb +2 -2
- data/spec/support/helper_methods.rb +0 -37
- data/spec/support/shared_examples/adapter.rb +0 -1
- data/spec/support/shared_examples/request_method.rb +0 -13
- metadata +11 -23
- data/lib/faraday/file_part.rb +0 -122
- data/lib/faraday/param_part.rb +0 -53
- data/lib/faraday/request/multipart.rb +0 -108
- data/lib/faraday/request/retry.rb +0 -241
- data/spec/faraday/composite_read_io_spec.rb +0 -80
- data/spec/faraday/request/multipart_spec.rb +0 -302
- data/spec/faraday/request/retry_spec.rb +0 -254
|
@@ -12,9 +12,9 @@ end
|
|
|
12
12
|
|
|
13
13
|
shared_examples 'initializer with url' do
|
|
14
14
|
context 'with simple url' do
|
|
15
|
-
let(:address) { 'http://
|
|
15
|
+
let(:address) { 'http://httpbingo.org' }
|
|
16
16
|
|
|
17
|
-
it { expect(subject.host).to eq('
|
|
17
|
+
it { expect(subject.host).to eq('httpbingo.org') }
|
|
18
18
|
it { expect(subject.port).to eq(80) }
|
|
19
19
|
it { expect(subject.scheme).to eq('http') }
|
|
20
20
|
it { expect(subject.path_prefix).to eq('/') }
|
|
@@ -22,7 +22,7 @@ shared_examples 'initializer with url' do
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
context 'with complex url' do
|
|
25
|
-
let(:address) { 'http://
|
|
25
|
+
let(:address) { 'http://httpbingo.org:815/fish?a=1' }
|
|
26
26
|
|
|
27
27
|
it { expect(subject.port).to eq(815) }
|
|
28
28
|
it { expect(subject.path_prefix).to eq('/fish') }
|
|
@@ -41,17 +41,17 @@ shared_examples 'default connection options' do
|
|
|
41
41
|
after { Faraday.default_connection_options = nil }
|
|
42
42
|
|
|
43
43
|
it 'works with implicit url' do
|
|
44
|
-
conn = Faraday.new 'http://
|
|
44
|
+
conn = Faraday.new 'http://httpbingo.org/foo'
|
|
45
45
|
expect(conn.options.timeout).to eq(10)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it 'works with option url' do
|
|
49
|
-
conn = Faraday.new url: 'http://
|
|
49
|
+
conn = Faraday.new url: 'http://httpbingo.org/foo'
|
|
50
50
|
expect(conn.options.timeout).to eq(10)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it 'works with instance connection options' do
|
|
54
|
-
conn = Faraday.new 'http://
|
|
54
|
+
conn = Faraday.new 'http://httpbingo.org/foo', request: { open_timeout: 1 }
|
|
55
55
|
expect(conn.options.timeout).to eq(10)
|
|
56
56
|
expect(conn.options.open_timeout).to eq(1)
|
|
57
57
|
end
|
|
@@ -61,7 +61,7 @@ shared_examples 'default connection options' do
|
|
|
61
61
|
conn.options.timeout = 1
|
|
62
62
|
expect(Faraday.default_connection_options.request.timeout).to eq(10)
|
|
63
63
|
|
|
64
|
-
other = Faraday.new url: 'https://
|
|
64
|
+
other = Faraday.new url: 'https://httpbingo.org/foo'
|
|
65
65
|
other.options.timeout = 1
|
|
66
66
|
|
|
67
67
|
expect(Faraday.default_connection_options.request.timeout).to eq(10)
|
|
@@ -81,14 +81,14 @@ RSpec.describe Faraday::Connection do
|
|
|
81
81
|
subject { conn }
|
|
82
82
|
|
|
83
83
|
context 'with implicit url param' do
|
|
84
|
-
# Faraday::Connection.new('http://
|
|
84
|
+
# Faraday::Connection.new('http://httpbingo.org')
|
|
85
85
|
let(:url) { address }
|
|
86
86
|
|
|
87
87
|
it_behaves_like 'initializer with url'
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
context 'with explicit url param' do
|
|
91
|
-
# Faraday::Connection.new(url: 'http://
|
|
91
|
+
# Faraday::Connection.new(url: 'http://httpbingo.org')
|
|
92
92
|
let(:url) { { url: address } }
|
|
93
93
|
|
|
94
94
|
it_behaves_like 'initializer with url'
|
|
@@ -108,13 +108,13 @@ RSpec.describe Faraday::Connection do
|
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
context 'with custom params and params in url' do
|
|
111
|
-
let(:url) { 'http://
|
|
111
|
+
let(:url) { 'http://httpbingo.org/fish?a=1&b=2' }
|
|
112
112
|
let(:options) { { params: { a: 3 } } }
|
|
113
113
|
it { expect(subject.params).to eq('a' => 3, 'b' => '2') }
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
context 'with basic_auth in url' do
|
|
117
|
-
let(:url) { 'http://Aladdin:open%20sesame@
|
|
117
|
+
let(:url) { 'http://Aladdin:open%20sesame@httpbingo.org/fish' }
|
|
118
118
|
|
|
119
119
|
it { expect(subject.headers['Authorization']).to eq('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==') }
|
|
120
120
|
end
|
|
@@ -141,7 +141,7 @@ RSpec.describe Faraday::Connection do
|
|
|
141
141
|
let(:conn) do
|
|
142
142
|
Faraday::Connection.new(params: { 'a' => '1' }) do |faraday|
|
|
143
143
|
faraday.adapter :test
|
|
144
|
-
faraday.url_prefix = 'http://
|
|
144
|
+
faraday.url_prefix = 'http://httpbingo.org/omnom'
|
|
145
145
|
end
|
|
146
146
|
end
|
|
147
147
|
|
|
@@ -151,6 +151,9 @@ RSpec.describe Faraday::Connection do
|
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
describe '#close' do
|
|
154
|
+
before { Faraday.default_adapter = :test }
|
|
155
|
+
after { Faraday.default_adapter = nil }
|
|
156
|
+
|
|
154
157
|
it 'can close underlying app' do
|
|
155
158
|
expect(conn.app).to receive(:close)
|
|
156
159
|
conn.close
|
|
@@ -162,8 +165,8 @@ RSpec.describe Faraday::Connection do
|
|
|
162
165
|
subject { conn.build_exclusive_url('sake.html') }
|
|
163
166
|
|
|
164
167
|
it 'uses connection host as default host' do
|
|
165
|
-
conn.host = '
|
|
166
|
-
expect(subject.host).to eq('
|
|
168
|
+
conn.host = 'httpbingo.org'
|
|
169
|
+
expect(subject.host).to eq('httpbingo.org')
|
|
167
170
|
expect(subject.scheme).to eq('http')
|
|
168
171
|
end
|
|
169
172
|
|
|
@@ -200,10 +203,10 @@ RSpec.describe Faraday::Connection do
|
|
|
200
203
|
end
|
|
201
204
|
|
|
202
205
|
context 'with complete url' do
|
|
203
|
-
subject { conn.build_exclusive_url('http://
|
|
206
|
+
subject { conn.build_exclusive_url('http://httpbingo.org/sake.html?a=1') }
|
|
204
207
|
|
|
205
208
|
it { expect(subject.scheme).to eq('http') }
|
|
206
|
-
it { expect(subject.host).to eq('
|
|
209
|
+
it { expect(subject.host).to eq('httpbingo.org') }
|
|
207
210
|
it { expect(subject.port).to eq(80) }
|
|
208
211
|
it { expect(subject.path).to eq('/sake.html') }
|
|
209
212
|
it { expect(subject.query).to eq('a=1') }
|
|
@@ -211,35 +214,35 @@ RSpec.describe Faraday::Connection do
|
|
|
211
214
|
|
|
212
215
|
it 'overrides connection port for absolute url' do
|
|
213
216
|
conn.port = 23
|
|
214
|
-
uri = conn.build_exclusive_url('http://
|
|
217
|
+
uri = conn.build_exclusive_url('http://httpbingo.org')
|
|
215
218
|
expect(uri.port).to eq(80)
|
|
216
219
|
end
|
|
217
220
|
|
|
218
221
|
it 'does not add ending slash given nil url' do
|
|
219
|
-
conn.url_prefix = 'http://
|
|
222
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
|
220
223
|
uri = conn.build_exclusive_url
|
|
221
224
|
expect(uri.path).to eq('/nigiri')
|
|
222
225
|
end
|
|
223
226
|
|
|
224
227
|
it 'does not add ending slash given empty url' do
|
|
225
|
-
conn.url_prefix = 'http://
|
|
228
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
|
226
229
|
uri = conn.build_exclusive_url('')
|
|
227
230
|
expect(uri.path).to eq('/nigiri')
|
|
228
231
|
end
|
|
229
232
|
|
|
230
233
|
it 'does not use connection params' do
|
|
231
|
-
conn.url_prefix = 'http://
|
|
234
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
|
232
235
|
conn.params = { a: 1 }
|
|
233
|
-
expect(conn.build_exclusive_url.to_s).to eq('http://
|
|
236
|
+
expect(conn.build_exclusive_url.to_s).to eq('http://httpbingo.org/nigiri')
|
|
234
237
|
end
|
|
235
238
|
|
|
236
239
|
it 'allows to provide params argument' do
|
|
237
|
-
conn.url_prefix = 'http://
|
|
240
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
|
238
241
|
conn.params = { a: 1 }
|
|
239
242
|
params = Faraday::Utils::ParamsHash.new
|
|
240
243
|
params[:a] = 2
|
|
241
244
|
uri = conn.build_exclusive_url(nil, params)
|
|
242
|
-
expect(uri.to_s).to eq('http://
|
|
245
|
+
expect(uri.to_s).to eq('http://httpbingo.org/nigiri?a=2')
|
|
243
246
|
end
|
|
244
247
|
|
|
245
248
|
it 'handles uri instances' do
|
|
@@ -248,34 +251,34 @@ RSpec.describe Faraday::Connection do
|
|
|
248
251
|
end
|
|
249
252
|
|
|
250
253
|
it 'always returns new URI instance' do
|
|
251
|
-
conn.url_prefix = 'http://
|
|
254
|
+
conn.url_prefix = 'http://httpbingo.org'
|
|
252
255
|
uri1 = conn.build_exclusive_url(nil)
|
|
253
256
|
uri2 = conn.build_exclusive_url(nil)
|
|
254
257
|
expect(uri1).not_to equal(uri2)
|
|
255
258
|
end
|
|
256
259
|
|
|
257
260
|
context 'with url_prefixed connection' do
|
|
258
|
-
let(:url) { 'http://
|
|
261
|
+
let(:url) { 'http://httpbingo.org/get/' }
|
|
259
262
|
|
|
260
263
|
it 'parses url and changes scheme' do
|
|
261
264
|
conn.scheme = 'https'
|
|
262
265
|
uri = conn.build_exclusive_url('sake.html')
|
|
263
|
-
expect(uri.to_s).to eq('https://
|
|
266
|
+
expect(uri.to_s).to eq('https://httpbingo.org/get/sake.html')
|
|
264
267
|
end
|
|
265
268
|
|
|
266
269
|
it 'joins url to base with ending slash' do
|
|
267
270
|
uri = conn.build_exclusive_url('sake.html')
|
|
268
|
-
expect(uri.to_s).to eq('http://
|
|
271
|
+
expect(uri.to_s).to eq('http://httpbingo.org/get/sake.html')
|
|
269
272
|
end
|
|
270
273
|
|
|
271
274
|
it 'used default base with ending slash' do
|
|
272
275
|
uri = conn.build_exclusive_url
|
|
273
|
-
expect(uri.to_s).to eq('http://
|
|
276
|
+
expect(uri.to_s).to eq('http://httpbingo.org/get/')
|
|
274
277
|
end
|
|
275
278
|
|
|
276
279
|
it 'overrides base' do
|
|
277
280
|
uri = conn.build_exclusive_url('/sake/')
|
|
278
|
-
expect(uri.to_s).to eq('http://
|
|
281
|
+
expect(uri.to_s).to eq('http://httpbingo.org/sake/')
|
|
279
282
|
end
|
|
280
283
|
end
|
|
281
284
|
|
|
@@ -304,22 +307,22 @@ RSpec.describe Faraday::Connection do
|
|
|
304
307
|
end
|
|
305
308
|
|
|
306
309
|
describe '#build_url' do
|
|
307
|
-
let(:url) { 'http://
|
|
310
|
+
let(:url) { 'http://httpbingo.org/nigiri' }
|
|
308
311
|
|
|
309
312
|
it 'uses params' do
|
|
310
313
|
conn.params = { a: 1, b: 1 }
|
|
311
|
-
expect(conn.build_url.to_s).to eq('http://
|
|
314
|
+
expect(conn.build_url.to_s).to eq('http://httpbingo.org/nigiri?a=1&b=1')
|
|
312
315
|
end
|
|
313
316
|
|
|
314
317
|
it 'merges params' do
|
|
315
318
|
conn.params = { a: 1, b: 1 }
|
|
316
319
|
url = conn.build_url(nil, b: 2, c: 3)
|
|
317
|
-
expect(url.to_s).to eq('http://
|
|
320
|
+
expect(url.to_s).to eq('http://httpbingo.org/nigiri?a=1&b=2&c=3')
|
|
318
321
|
end
|
|
319
322
|
end
|
|
320
323
|
|
|
321
324
|
describe '#build_request' do
|
|
322
|
-
let(:url) { 'https://
|
|
325
|
+
let(:url) { 'https://ahttpbingo.org/sake.html' }
|
|
323
326
|
let(:request) { conn.build_request(:get) }
|
|
324
327
|
|
|
325
328
|
before do
|
|
@@ -336,7 +339,7 @@ RSpec.describe Faraday::Connection do
|
|
|
336
339
|
describe '#to_env' do
|
|
337
340
|
subject { conn.build_request(:get).to_env(conn).url }
|
|
338
341
|
|
|
339
|
-
let(:url) { 'http://
|
|
342
|
+
let(:url) { 'http://httpbingo.org/sake.html' }
|
|
340
343
|
let(:options) { { params: @params } }
|
|
341
344
|
|
|
342
345
|
it 'parses url params into query' do
|
|
@@ -589,7 +592,7 @@ RSpec.describe Faraday::Connection do
|
|
|
589
592
|
describe '#dup' do
|
|
590
593
|
subject { conn.dup }
|
|
591
594
|
|
|
592
|
-
let(:url) { 'http://
|
|
595
|
+
let(:url) { 'http://httpbingo.org/foo' }
|
|
593
596
|
let(:options) do
|
|
594
597
|
{
|
|
595
598
|
ssl: { verify: :none },
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Faraday::MiddlewareRegistry do
|
|
4
|
+
before do
|
|
5
|
+
stub_const('CustomMiddleware', custom_middleware_klass)
|
|
6
|
+
end
|
|
7
|
+
let(:custom_middleware_klass) { Class.new(Faraday::Middleware) }
|
|
8
|
+
let(:dummy) { Class.new { extend Faraday::MiddlewareRegistry } }
|
|
9
|
+
|
|
10
|
+
after { dummy.unregister_middleware(:custom) }
|
|
11
|
+
|
|
12
|
+
it 'allows to register with constant' do
|
|
13
|
+
dummy.register_middleware(custom: custom_middleware_klass)
|
|
14
|
+
expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'allows to register with symbol' do
|
|
18
|
+
dummy.register_middleware(custom: :CustomMiddleware)
|
|
19
|
+
expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'allows to register with string' do
|
|
23
|
+
dummy.register_middleware(custom: 'CustomMiddleware')
|
|
24
|
+
expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'allows to register with Proc' do
|
|
28
|
+
dummy.register_middleware(custom: -> { custom_middleware_klass })
|
|
29
|
+
expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -20,6 +20,8 @@ RSpec.describe Faraday::RackBuilder do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
subject { conn.builder }
|
|
23
|
+
before { Faraday.default_adapter = :test }
|
|
24
|
+
after { Faraday.default_adapter = nil }
|
|
23
25
|
|
|
24
26
|
context 'with default stack' do
|
|
25
27
|
let(:conn) { Faraday::Connection.new }
|
|
@@ -86,13 +88,6 @@ RSpec.describe Faraday::RackBuilder do
|
|
|
86
88
|
|
|
87
89
|
it { expect(subject.handlers).to eq([Apple]) }
|
|
88
90
|
|
|
89
|
-
it 'allows rebuilding' do
|
|
90
|
-
subject.build do |builder|
|
|
91
|
-
builder.use(Orange)
|
|
92
|
-
end
|
|
93
|
-
expect(subject.handlers).to eq([Orange])
|
|
94
|
-
end
|
|
95
|
-
|
|
96
91
|
it 'allows use' do
|
|
97
92
|
subject.use(Orange)
|
|
98
93
|
expect(subject.handlers).to eq([Apple, Orange])
|
|
@@ -115,18 +110,6 @@ RSpec.describe Faraday::RackBuilder do
|
|
|
115
110
|
end
|
|
116
111
|
end
|
|
117
112
|
|
|
118
|
-
context 'with custom registered middleware' do
|
|
119
|
-
let(:conn) { Faraday::Connection.new {} }
|
|
120
|
-
|
|
121
|
-
after { Faraday::Middleware.unregister_middleware(:apple) }
|
|
122
|
-
|
|
123
|
-
it 'allows to register with constant' do
|
|
124
|
-
Faraday::Middleware.register_middleware(apple: Apple)
|
|
125
|
-
subject.use(:apple)
|
|
126
|
-
expect(subject.handlers).to eq([Apple])
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
113
|
context 'when having two handlers' do
|
|
131
114
|
let(:conn) { Faraday::Connection.new {} }
|
|
132
115
|
|
|
@@ -156,6 +139,33 @@ RSpec.describe Faraday::RackBuilder do
|
|
|
156
139
|
end
|
|
157
140
|
end
|
|
158
141
|
|
|
142
|
+
context 'when adapter is added with named options' do
|
|
143
|
+
after { Faraday.default_adapter_options = {} }
|
|
144
|
+
let(:conn) { Faraday::Connection.new {} }
|
|
145
|
+
|
|
146
|
+
let(:cat_adapter) do
|
|
147
|
+
Class.new(Faraday::Adapter) do
|
|
148
|
+
attr_accessor :name
|
|
149
|
+
|
|
150
|
+
def initialize(app, name:)
|
|
151
|
+
super(app)
|
|
152
|
+
@name = name
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
let(:cat) { subject.adapter.build }
|
|
158
|
+
|
|
159
|
+
it 'adds a handler to construct adapter with named options' do
|
|
160
|
+
Faraday.default_adapter = cat_adapter
|
|
161
|
+
Faraday.default_adapter_options = { name: 'Chloe' }
|
|
162
|
+
expect { cat }.to_not output(
|
|
163
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
|
164
|
+
).to_stderr
|
|
165
|
+
expect(cat.name).to eq 'Chloe'
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
159
169
|
context 'when middleware is added with named arguments' do
|
|
160
170
|
let(:conn) { Faraday::Connection.new {} }
|
|
161
171
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
RSpec.describe Faraday::Request do
|
|
4
4
|
let(:conn) do
|
|
5
|
-
Faraday.new(url: 'http://
|
|
5
|
+
Faraday.new(url: 'http://httpbingo.org/api',
|
|
6
6
|
headers: { 'Mime-Version' => '1.0' },
|
|
7
7
|
request: { oauth: { consumer_key: 'anonymous' } })
|
|
8
8
|
end
|
|
@@ -27,7 +27,7 @@ RSpec.describe Faraday::Request do
|
|
|
27
27
|
|
|
28
28
|
it { expect(subject.path).to eq(URI.parse('foo.json')) }
|
|
29
29
|
it { expect(subject.params).to eq('a' => '1') }
|
|
30
|
-
it { expect(subject.to_env(conn).url.to_s).to eq('http://
|
|
30
|
+
it { expect(subject.to_env(conn).url.to_s).to eq('http://httpbingo.org/api/foo.json?a=1') }
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
context 'when setting the url on setup with a string path and params' do
|
|
@@ -35,7 +35,7 @@ RSpec.describe Faraday::Request do
|
|
|
35
35
|
|
|
36
36
|
it { expect(subject.path).to eq('foo.json') }
|
|
37
37
|
it { expect(subject.params).to eq('a' => 1) }
|
|
38
|
-
it { expect(subject.to_env(conn).url.to_s).to eq('http://
|
|
38
|
+
it { expect(subject.to_env(conn).url.to_s).to eq('http://httpbingo.org/api/foo.json?a=1') }
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context 'when setting the url on setup with a path including params' do
|
|
@@ -43,7 +43,7 @@ RSpec.describe Faraday::Request do
|
|
|
43
43
|
|
|
44
44
|
it { expect(subject.path).to eq('foo.json') }
|
|
45
45
|
it { expect(subject.params).to eq('a' => '1', 'b' => '2') }
|
|
46
|
-
it { expect(subject.to_env(conn).url.to_s).to eq('http://
|
|
46
|
+
it { expect(subject.to_env(conn).url.to_s).to eq('http://httpbingo.org/api/foo.json?a=1&b=2') }
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
context 'when setting a header on setup with []= syntax' do
|
|
@@ -68,9 +68,9 @@ RSpec.describe Faraday::Utils::Headers do
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
context 'when response headers values include a colon' do
|
|
71
|
-
let(:headers) { "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://
|
|
71
|
+
let(:headers) { "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://httpbingo.org/\r\n\r\n" }
|
|
72
72
|
|
|
73
|
-
it { expect(subject['location']).to eq('http://
|
|
73
|
+
it { expect(subject['location']).to eq('http://httpbingo.org/') }
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
context 'when response headers include a blank line' do
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'multipart_parser/reader'
|
|
4
|
-
|
|
5
3
|
module Faraday
|
|
6
4
|
module HelperMethods
|
|
7
5
|
def self.included(base)
|
|
@@ -86,41 +84,6 @@ module Faraday
|
|
|
86
84
|
end
|
|
87
85
|
end
|
|
88
86
|
|
|
89
|
-
def multipart_file
|
|
90
|
-
Faraday::FilePart.new(__FILE__, 'text/x-ruby')
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# parse boundary out of a Content-Type header like:
|
|
94
|
-
# Content-Type: multipart/form-data; boundary=gc0p4Jq0M2Yt08jU534c0p
|
|
95
|
-
def parse_multipart_boundary(ctype)
|
|
96
|
-
MultipartParser::Reader.extract_boundary_value(ctype)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# parse a multipart MIME message, returning a hash of any multipart errors
|
|
100
|
-
def parse_multipart(boundary, body)
|
|
101
|
-
reader = MultipartParser::Reader.new(boundary)
|
|
102
|
-
result = { errors: [], parts: [] }
|
|
103
|
-
def result.part(name)
|
|
104
|
-
hash = self[:parts].detect { |h| h[:part].name == name }
|
|
105
|
-
[hash[:part], hash[:body].join]
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
reader.on_part do |part|
|
|
109
|
-
result[:parts] << thispart = {
|
|
110
|
-
part: part,
|
|
111
|
-
body: []
|
|
112
|
-
}
|
|
113
|
-
part.on_data do |chunk|
|
|
114
|
-
thispart[:body] << chunk
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
reader.on_error do |msg|
|
|
118
|
-
result[:errors] << msg
|
|
119
|
-
end
|
|
120
|
-
reader.write(body)
|
|
121
|
-
result
|
|
122
|
-
end
|
|
123
|
-
|
|
124
87
|
def method_with_body?(method)
|
|
125
88
|
self.class.method_with_body?(method)
|
|
126
89
|
end
|
|
@@ -40,7 +40,6 @@ shared_examples 'adapter examples' do |**options|
|
|
|
40
40
|
conn_options[:ssl][:ca_file] ||= ENV['SSL_FILE']
|
|
41
41
|
|
|
42
42
|
Faraday.new(remote, conn_options) do |conn|
|
|
43
|
-
conn.request :multipart
|
|
44
43
|
conn.request :url_encoded
|
|
45
44
|
conn.response :raise_error
|
|
46
45
|
conn.adapter described_class, *adapter_options
|
|
@@ -126,19 +126,6 @@ shared_examples 'a request method' do |http_method|
|
|
|
126
126
|
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
# Can't send files on get, head and delete methods
|
|
130
|
-
if method_with_body?(http_method)
|
|
131
|
-
it 'sends files' do
|
|
132
|
-
payload = { uploaded_file: multipart_file }
|
|
133
|
-
request_stub.with(headers: { 'Content-Type' => %r{\Amultipart/form-data} }) do |request|
|
|
134
|
-
# WebMock does not support matching body for multipart/form-data requests yet :(
|
|
135
|
-
# https://github.com/bblimke/webmock/issues/623
|
|
136
|
-
request.body.include?('RubyMultipartPost')
|
|
137
|
-
end
|
|
138
|
-
conn.public_send(http_method, '/', payload)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
129
|
on_feature :reason_phrase_parse do
|
|
143
130
|
it 'parses the reason phrase' do
|
|
144
131
|
request_stub.to_return(status: [200, 'OK'])
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: faraday
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "@technoweenie"
|
|
@@ -10,28 +10,22 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
16
|
+
name: faraday-net_http
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
|
-
- - "
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: '1.2'
|
|
22
|
-
- - "<"
|
|
19
|
+
- - "~>"
|
|
23
20
|
- !ruby/object:Gem::Version
|
|
24
|
-
version: '
|
|
21
|
+
version: '2.0'
|
|
25
22
|
type: :runtime
|
|
26
23
|
prerelease: false
|
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
28
25
|
requirements:
|
|
29
|
-
- - "
|
|
26
|
+
- - "~>"
|
|
30
27
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '
|
|
32
|
-
- - "<"
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: '3'
|
|
28
|
+
version: '2.0'
|
|
35
29
|
- !ruby/object:Gem::Dependency
|
|
36
30
|
name: ruby2_keywords
|
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,7 +60,6 @@ files:
|
|
|
66
60
|
- lib/faraday/encoders/flat_params_encoder.rb
|
|
67
61
|
- lib/faraday/encoders/nested_params_encoder.rb
|
|
68
62
|
- lib/faraday/error.rb
|
|
69
|
-
- lib/faraday/file_part.rb
|
|
70
63
|
- lib/faraday/logging/formatter.rb
|
|
71
64
|
- lib/faraday/methods.rb
|
|
72
65
|
- lib/faraday/middleware.rb
|
|
@@ -77,15 +70,12 @@ files:
|
|
|
77
70
|
- lib/faraday/options/proxy_options.rb
|
|
78
71
|
- lib/faraday/options/request_options.rb
|
|
79
72
|
- lib/faraday/options/ssl_options.rb
|
|
80
|
-
- lib/faraday/param_part.rb
|
|
81
73
|
- lib/faraday/parameters.rb
|
|
82
74
|
- lib/faraday/rack_builder.rb
|
|
83
75
|
- lib/faraday/request.rb
|
|
84
76
|
- lib/faraday/request/authorization.rb
|
|
85
77
|
- lib/faraday/request/instrumentation.rb
|
|
86
78
|
- lib/faraday/request/json.rb
|
|
87
|
-
- lib/faraday/request/multipart.rb
|
|
88
|
-
- lib/faraday/request/retry.rb
|
|
89
79
|
- lib/faraday/request/url_encoded.rb
|
|
90
80
|
- lib/faraday/response.rb
|
|
91
81
|
- lib/faraday/response/json.rb
|
|
@@ -99,9 +89,9 @@ files:
|
|
|
99
89
|
- spec/faraday/adapter/test_spec.rb
|
|
100
90
|
- spec/faraday/adapter_registry_spec.rb
|
|
101
91
|
- spec/faraday/adapter_spec.rb
|
|
102
|
-
- spec/faraday/composite_read_io_spec.rb
|
|
103
92
|
- spec/faraday/connection_spec.rb
|
|
104
93
|
- spec/faraday/error_spec.rb
|
|
94
|
+
- spec/faraday/middleware_registry_spec.rb
|
|
105
95
|
- spec/faraday/middleware_spec.rb
|
|
106
96
|
- spec/faraday/options/env_spec.rb
|
|
107
97
|
- spec/faraday/options/options_spec.rb
|
|
@@ -113,8 +103,6 @@ files:
|
|
|
113
103
|
- spec/faraday/request/authorization_spec.rb
|
|
114
104
|
- spec/faraday/request/instrumentation_spec.rb
|
|
115
105
|
- spec/faraday/request/json_spec.rb
|
|
116
|
-
- spec/faraday/request/multipart_spec.rb
|
|
117
|
-
- spec/faraday/request/retry_spec.rb
|
|
118
106
|
- spec/faraday/request/url_encoded_spec.rb
|
|
119
107
|
- spec/faraday/request_spec.rb
|
|
120
108
|
- spec/faraday/response/json_spec.rb
|
|
@@ -137,7 +125,7 @@ licenses:
|
|
|
137
125
|
- MIT
|
|
138
126
|
metadata:
|
|
139
127
|
homepage_uri: https://lostisland.github.io/faraday
|
|
140
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
|
128
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.2.0
|
|
141
129
|
source_code_uri: https://github.com/lostisland/faraday
|
|
142
130
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
|
143
131
|
post_install_message:
|
|
@@ -152,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
152
140
|
version: '2.6'
|
|
153
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
142
|
requirements:
|
|
155
|
-
- - "
|
|
143
|
+
- - ">="
|
|
156
144
|
- !ruby/object:Gem::Version
|
|
157
|
-
version:
|
|
145
|
+
version: '0'
|
|
158
146
|
requirements: []
|
|
159
147
|
rubygems_version: 3.1.6
|
|
160
148
|
signing_key:
|