faraday 2.0.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +81 -3
- data/README.md +0 -5
- data/examples/client_spec.rb +18 -18
- data/examples/client_test.rb +21 -21
- data/lib/faraday/adapter/test.rb +8 -4
- data/lib/faraday/connection.rb +7 -7
- data/lib/faraday/encoders/nested_params_encoder.rb +11 -4
- data/lib/faraday/middleware_registry.rb +19 -1
- data/lib/faraday/rack_builder.rb +2 -2
- data/lib/faraday/request/url_encoded.rb +3 -1
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +6 -1
- data/spec/faraday/connection_spec.rb +35 -35
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/params_encoders/nested_spec.rb +8 -0
- data/spec/faraday/rack_builder_spec.rb +27 -12
- data/spec/faraday/request/url_encoded_spec.rb +12 -1
- data/spec/faraday/request_spec.rb +4 -4
- data/spec/faraday/utils/headers_spec.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51764b6108e230dfff244e6e6e9f275f92f5fc1bcd1bf8e43d36058d35442e14
|
4
|
+
data.tar.gz: 2cdf2edfd3e3c0386f501c0c2609db4f5c879a2a1807869a7b7e690e4a22a77a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94ce1d0df0639d8e7a8472085331796a787236989e07943a47e463f6d5c68d83bf180b55636e87d37ac654400fe11660ee10898c9b43122c29a211310682b621
|
7
|
+
data.tar.gz: 14af6c0c348cf3ca8ae7f7f8a95b3eb8b73b8a444d90a75c7eeb46d9edd4c840fa44dd2eda4e76653fd4924e6b20d13f32236e21bd303f90b589df1abc88da3d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,83 @@
|
|
1
1
|
# Faraday Changelog
|
2
2
|
|
3
|
+
## The changelog has moved!
|
4
|
+
|
5
|
+
This file is not being updated anymore. Instead, please check the [Releases](https://github.com/lostisland/faraday/releases) page.
|
6
|
+
|
7
|
+
## [2.2.0](https://github.com/lostisland/faraday/compare/v2.1.0...v2.2.0) (2022-02-03)
|
8
|
+
|
9
|
+
* Reintroduce the possibility to register middleware with symbols, strings or procs in [#1391](https://github.com/lostisland/faraday/pull/1391)
|
10
|
+
|
11
|
+
## [2.1.0](https://github.com/lostisland/faraday/compare/v2.0.1...v2.1.0) (2022-01-15)
|
12
|
+
|
13
|
+
* Fix test adapter thread safety by @iMacTia in [#1380](https://github.com/lostisland/faraday/pull/1380)
|
14
|
+
* Add default adapter options by @hirasawayuki in [#1382](https://github.com/lostisland/faraday/pull/1382)
|
15
|
+
* CI: Add Ruby 3.1 to matrix by @petergoldstein in [#1374](https://github.com/lostisland/faraday/pull/1374)
|
16
|
+
* docs: fix regex pattern in logger.md examples by @hirasawayuki in [#1378](https://github.com/lostisland/faraday/pull/1378)
|
17
|
+
|
18
|
+
## [2.0.1](https://github.com/lostisland/faraday/compare/v2.0.0...v2.0.1) (2022-01-05)
|
19
|
+
|
20
|
+
* Re-add `faraday-net_http` as default adapter by @iMacTia in [#1366](https://github.com/lostisland/faraday/pull/1366)
|
21
|
+
* Updated sample format in UPGRADING.md by @vimutter in [#1361](https://github.com/lostisland/faraday/pull/1361)
|
22
|
+
* docs: Make UPGRADING examples more copyable by @olleolleolle in [#1363](https://github.com/lostisland/faraday/pull/1363)
|
23
|
+
|
24
|
+
## [2.0.0](https://github.com/lostisland/faraday/compare/v1.8.0...v2.0.0) (2022-01-04)
|
25
|
+
|
26
|
+
The next major release is here, and it comes almost 2 years after the release of v1.0!
|
27
|
+
|
28
|
+
This release changes the way you use Faraday and embraces a new paradigm of Faraday as an ecosystem, rather than a library.
|
29
|
+
|
30
|
+
What does that mean? It means that Faraday is less of a bundled tool and more of a framework for the community to build on top of.
|
31
|
+
|
32
|
+
As a result, all adapters and some middleware have moved out and are now shipped as standalone gems 🙌!
|
33
|
+
|
34
|
+
But this doesn't mean that upgrading from Faraday 1.x to Faraday 2.0 should be hard, in fact we've listed everything you need to do in the [UPGRADING.md](https://github.com/lostisland/faraday/blob/main/UPGRADING.md) doc.
|
35
|
+
|
36
|
+
Moreover, we've setup a new [awesome-faraday](https://github.com/lostisland/awesome-faraday) repository that will showcase a curated list of adapters and middleware 😎.
|
37
|
+
|
38
|
+
This release was the result of the efforts of the core team and all the contributors, new and old, that have helped achieve this milestone 👏.
|
39
|
+
|
40
|
+
## What's Changed
|
41
|
+
|
42
|
+
* Autoloading, dependency loading and middleware registry cleanup by @iMacTia in [#1301](https://github.com/lostisland/faraday/pull/1301)
|
43
|
+
* Move JSON middleware (request and response) from faraday_middleware by @iMacTia in [#1300](https://github.com/lostisland/faraday/pull/1300)
|
44
|
+
* Remove deprecated `Faraday::Request#method` by @olleolleolle in [#1303](https://github.com/lostisland/faraday/pull/1303)
|
45
|
+
* Remove deprecated `Faraday::UploadIO` by @iMacTia in [#1307](https://github.com/lostisland/faraday/pull/1307)
|
46
|
+
* [1.x] Deprecate Authorization helpers in `Faraday::Connection` by @iMacTia in [#1306](https://github.com/lostisland/faraday/pull/1306)
|
47
|
+
* Drop deprecated auth helpers from Connection and refactor auth middleware by @iMacTia in [#1308](https://github.com/lostisland/faraday/pull/1308)
|
48
|
+
* Add Faraday 1.x examples in authentication.md docs by @iMacTia in [#1320](https://github.com/lostisland/faraday/pull/1320)
|
49
|
+
* Fix passing a URL with embedded basic auth by @iMacTia in [#1324](https://github.com/lostisland/faraday/pull/1324)
|
50
|
+
* Register JSON middleware by @mollerhoj in [#1331](https://github.com/lostisland/faraday/pull/1331)
|
51
|
+
* Retry middleware should handle string exception class name consistently by @jrochkind in [#1334](https://github.com/lostisland/faraday/pull/1334)
|
52
|
+
* Improve request info in exceptions raised by RaiseError Middleware by @willianzocolau in [#1335](https://github.com/lostisland/faraday/pull/1335)
|
53
|
+
* Remove net-http adapter and update docs by @iMacTia in [#1336](https://github.com/lostisland/faraday/pull/1336)
|
54
|
+
* Explain plan for faraday_middleware in UPGRADING.md by @iMacTia in [#1339](https://github.com/lostisland/faraday/pull/1339)
|
55
|
+
* Scripts folder cleanup by @iMacTia in [#1340](https://github.com/lostisland/faraday/pull/1340)
|
56
|
+
* Replace `Hash#merge` with `Utils#deep_merge` for connection options by @xkwd in [#1343](https://github.com/lostisland/faraday/pull/1343)
|
57
|
+
* Callable authorizers by @sled in [#1345](https://github.com/lostisland/faraday/pull/1345)
|
58
|
+
* Default value for exc error by @DariuszMusielak in [#1351](https://github.com/lostisland/faraday/pull/1351)
|
59
|
+
* Don't call `retry_block` unless a retry is going to happen by @jrochkind in [#1350](https://github.com/lostisland/faraday/pull/1350)
|
60
|
+
* Improve documentation for v2 by @iMacTia in [#1353](https://github.com/lostisland/faraday/pull/1353)
|
61
|
+
* Remove default `default_adapter` (yes, you read that right) by @iMacTia in [#1354](https://github.com/lostisland/faraday/pull/1354)
|
62
|
+
* Remove retry middleware by @iMacTia in [#1356](https://github.com/lostisland/faraday/pull/1356)
|
63
|
+
* Remove multipart middleware and all its documentation and tests by @iMacTia in [#1357](https://github.com/lostisland/faraday/pull/1357)
|
64
|
+
|
65
|
+
## [1.9.3](https://github.com/lostisland/faraday/compare/v1.9.2...v1.9.3) (2022-01-06)
|
66
|
+
|
67
|
+
* Re-add support for Ruby 2.4+ by @iMacTia in [#1371](https://github.com/lostisland/faraday/pull/1371)
|
68
|
+
|
69
|
+
## [1.9.2](https://github.com/lostisland/faraday/compare/v1.9.1...v1.9.2) (2022-01-06)
|
70
|
+
|
71
|
+
* Add alias with legacy name to gemified middleware by @iMacTia in [#1372](https://github.com/lostisland/faraday/pull/1372)
|
72
|
+
|
73
|
+
## [1.9.1](https://github.com/lostisland/faraday/compare/v1.9.0...v1.9.1) (2022-01-06)
|
74
|
+
|
75
|
+
* Update adapter dependencies in Gemspec by @iMacTia in [#1370](https://github.com/lostisland/faraday/pull/1370)
|
76
|
+
|
77
|
+
## [1.9.0](https://github.com/lostisland/faraday/compare/v1.8.0...v1.9.0) (2022-01-06)
|
78
|
+
|
79
|
+
* Use external multipart and retry middleware by @iMacTia in [#1367](https://github.com/lostisland/faraday/pull/1367)
|
80
|
+
|
3
81
|
## [1.8.0](https://github.com/lostisland/faraday/releases/tag/v1.8.0) (2021-09-18)
|
4
82
|
|
5
83
|
### Features
|
@@ -65,7 +143,7 @@
|
|
65
143
|
|
66
144
|
### Highlights
|
67
145
|
|
68
|
-
With this release, we continue the work of gradually moving out adapters into their own gems 🎉
|
146
|
+
With this release, we continue the work of gradually moving out adapters into their own gems 🎉
|
69
147
|
Thanks to @MikeRogers0 for helping the Faraday team in progressing with this quest 👏
|
70
148
|
|
71
149
|
And thanks to @olleolleolle efforts, Faraday is becoming more inclusive than ever 🤗
|
@@ -112,7 +190,7 @@ Checkout the "Misc" section below for more details 🙌 !
|
|
112
190
|
## [v1.3.0](https://github.com/lostisland/faraday/releases/tag/v1.3.0) (2020-12-31)
|
113
191
|
|
114
192
|
### Highlights
|
115
|
-
Faraday v1.3.0 is the first release to officially support Ruby 3.0 in the CI pipeline 🎉 🍾!
|
193
|
+
Faraday v1.3.0 is the first release to officially support Ruby 3.0 in the CI pipeline 🎉 🍾!
|
116
194
|
|
117
195
|
This is also the first release with a previously "included" adapter (Net::HTTP) being isolated into a [separate gem](https://github.com/lostisland/faraday-net_http) 🎊!
|
118
196
|
The new adapter is added to Faraday as a dependency for now, so that means full backwards-compatibility, but just to be safe be careful when upgrading!
|
@@ -203,7 +281,7 @@ Many thanks to the Faraday Team, @JanDintel and everyone who attended the [ROSS
|
|
203
281
|
* Allows `parse` method to be private/protected in response middleware (#1123)
|
204
282
|
* Encode Spaces in Query Strings as '%20' Instead of '+' (#1125)
|
205
283
|
* Limits rack to v2.0.x (#1127)
|
206
|
-
* Adapter Registry reads also use mutex (#1136)
|
284
|
+
* Adapter Registry reads also use mutex (#1136)
|
207
285
|
|
208
286
|
### Documentation
|
209
287
|
|
data/README.md
CHANGED
@@ -10,11 +10,6 @@ adapters (such as Net::HTTP) and embraces the concept of Rack middleware when pr
|
|
10
10
|
You probably don't want to use Faraday directly in your project, as it will lack an actual client library to perform
|
11
11
|
requests. Instead, you probably want to have a look at [Awesome Faraday][awesome] for a list of available adapters.
|
12
12
|
|
13
|
-
## FARADAY 2.0
|
14
|
-
|
15
|
-
You're reading the README and looking at the code of our upcoming v2.0 release (the `main` branch, currently in alpha).
|
16
|
-
If you're here to read about our latest v1.x release, then please head over to the [1.x branch](https://github.com/lostisland/faraday/tree/1.x).
|
17
|
-
|
18
13
|
## Getting Started
|
19
14
|
|
20
15
|
The best starting point is the [Faraday Website][website], with its introduction and explanation.
|
data/examples/client_spec.rb
CHANGED
@@ -12,10 +12,10 @@ class Client
|
|
12
12
|
@conn = conn
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def httpbingo(jname, params: {})
|
16
16
|
res = @conn.get("/#{jname}", params)
|
17
17
|
data = JSON.parse(res.body)
|
18
|
-
data['
|
18
|
+
data['origin']
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,42 +24,42 @@ RSpec.describe Client do
|
|
24
24
|
let(:conn) { Faraday.new { |b| b.adapter(:test, stubs) } }
|
25
25
|
let(:client) { Client.new(conn) }
|
26
26
|
|
27
|
-
it 'parses
|
28
|
-
stubs.get('/
|
27
|
+
it 'parses origin' do
|
28
|
+
stubs.get('/ip') do |env|
|
29
29
|
# optional: you can inspect the Faraday::Env
|
30
|
-
expect(env.url.path).to eq('/
|
30
|
+
expect(env.url.path).to eq('/ip')
|
31
31
|
[
|
32
32
|
200,
|
33
33
|
{ 'Content-Type': 'application/javascript' },
|
34
|
-
'{"
|
34
|
+
'{"origin": "127.0.0.1"}'
|
35
35
|
]
|
36
36
|
end
|
37
37
|
|
38
38
|
# uncomment to trigger stubs.verify_stubbed_calls failure
|
39
39
|
# stubs.get('/unused') { [404, {}, ''] }
|
40
40
|
|
41
|
-
expect(client.
|
41
|
+
expect(client.httpbingo('ip')).to eq('127.0.0.1')
|
42
42
|
stubs.verify_stubbed_calls
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'handles 404' do
|
46
|
-
stubs.get('/
|
46
|
+
stubs.get('/api') do
|
47
47
|
[
|
48
48
|
404,
|
49
49
|
{ 'Content-Type': 'application/javascript' },
|
50
50
|
'{}'
|
51
51
|
]
|
52
52
|
end
|
53
|
-
expect(client.
|
53
|
+
expect(client.httpbingo('api')).to be_nil
|
54
54
|
stubs.verify_stubbed_calls
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'handles exception' do
|
58
|
-
stubs.get('/
|
58
|
+
stubs.get('/api') do
|
59
59
|
raise Faraday::ConnectionFailed
|
60
60
|
end
|
61
61
|
|
62
|
-
expect { client.
|
62
|
+
expect { client.httpbingo('api') }.to raise_error(Faraday::ConnectionFailed)
|
63
63
|
stubs.verify_stubbed_calls
|
64
64
|
end
|
65
65
|
|
@@ -67,17 +67,17 @@ RSpec.describe Client do
|
|
67
67
|
let(:stubs) { Faraday::Adapter::Test::Stubs.new(strict_mode: true) }
|
68
68
|
|
69
69
|
it 'verifies the all parameter values are identical' do
|
70
|
-
stubs.get('/
|
70
|
+
stubs.get('/api?abc=123') do
|
71
71
|
[
|
72
72
|
200,
|
73
73
|
{ 'Content-Type': 'application/javascript' },
|
74
|
-
'{"
|
74
|
+
'{"origin": "127.0.0.1"}'
|
75
75
|
]
|
76
76
|
end
|
77
77
|
|
78
78
|
# uncomment to raise Stubs::NotFound
|
79
|
-
# expect(client.
|
80
|
-
expect(client.
|
79
|
+
# expect(client.httpbingo('api', params: { abc: 123, foo: 'Kappa' })).to eq('127.0.0.1')
|
80
|
+
expect(client.httpbingo('api', params: { abc: 123 })).to eq('127.0.0.1')
|
81
81
|
stubs.verify_stubbed_calls
|
82
82
|
end
|
83
83
|
end
|
@@ -86,11 +86,11 @@ RSpec.describe Client do
|
|
86
86
|
let(:conn) { Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) { |b| b.adapter(:test, stubs) } }
|
87
87
|
|
88
88
|
it 'handles the same multiple URL parameters' do
|
89
|
-
stubs.get('/
|
89
|
+
stubs.get('/api?a=x&a=y&a=z') { [200, { 'Content-Type' => 'application/json' }, '{"origin": "127.0.0.1"}'] }
|
90
90
|
|
91
91
|
# uncomment to raise Stubs::NotFound
|
92
|
-
# expect(client.
|
93
|
-
expect(client.
|
92
|
+
# expect(client.httpbingo('api', params: { a: %w[x y] })).to eq('127.0.0.1')
|
93
|
+
expect(client.httpbingo('api', params: { a: %w[x y z] })).to eq('127.0.0.1')
|
94
94
|
stubs.verify_stubbed_calls
|
95
95
|
end
|
96
96
|
end
|
data/examples/client_test.rb
CHANGED
@@ -13,24 +13,24 @@ class Client
|
|
13
13
|
@conn = conn
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def httpbingo(jname, params: {})
|
17
17
|
res = @conn.get("/#{jname}", params)
|
18
18
|
data = JSON.parse(res.body)
|
19
|
-
data['
|
19
|
+
data['origin']
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# Example API client test
|
24
24
|
class ClientTest < Test::Unit::TestCase
|
25
|
-
def
|
25
|
+
def test_httpbingo_name
|
26
26
|
stubs = Faraday::Adapter::Test::Stubs.new
|
27
|
-
stubs.get('/
|
27
|
+
stubs.get('/api') do |env|
|
28
28
|
# optional: you can inspect the Faraday::Env
|
29
|
-
assert_equal '/
|
29
|
+
assert_equal '/api', env.url.path
|
30
30
|
[
|
31
31
|
200,
|
32
32
|
{ 'Content-Type': 'application/javascript' },
|
33
|
-
'{"
|
33
|
+
'{"origin": "127.0.0.1"}'
|
34
34
|
]
|
35
35
|
end
|
36
36
|
|
@@ -38,13 +38,13 @@ class ClientTest < Test::Unit::TestCase
|
|
38
38
|
# stubs.get('/unused') { [404, {}, ''] }
|
39
39
|
|
40
40
|
cli = client(stubs)
|
41
|
-
assert_equal '
|
41
|
+
assert_equal '127.0.0.1', cli.httpbingo('api')
|
42
42
|
stubs.verify_stubbed_calls
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def test_httpbingo_not_found
|
46
46
|
stubs = Faraday::Adapter::Test::Stubs.new
|
47
|
-
stubs.get('/
|
47
|
+
stubs.get('/api') do
|
48
48
|
[
|
49
49
|
404,
|
50
50
|
{ 'Content-Type': 'application/javascript' },
|
@@ -53,48 +53,48 @@ class ClientTest < Test::Unit::TestCase
|
|
53
53
|
end
|
54
54
|
|
55
55
|
cli = client(stubs)
|
56
|
-
assert_nil cli.
|
56
|
+
assert_nil cli.httpbingo('api')
|
57
57
|
stubs.verify_stubbed_calls
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def test_httpbingo_exception
|
61
61
|
stubs = Faraday::Adapter::Test::Stubs.new
|
62
|
-
stubs.get('/
|
62
|
+
stubs.get('/api') do
|
63
63
|
raise Faraday::ConnectionFailed
|
64
64
|
end
|
65
65
|
|
66
66
|
cli = client(stubs)
|
67
67
|
assert_raise Faraday::ConnectionFailed do
|
68
|
-
cli.
|
68
|
+
cli.httpbingo('api')
|
69
69
|
end
|
70
70
|
stubs.verify_stubbed_calls
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_strict_mode
|
74
74
|
stubs = Faraday::Adapter::Test::Stubs.new(strict_mode: true)
|
75
|
-
stubs.get('/
|
75
|
+
stubs.get('/api?abc=123') do
|
76
76
|
[
|
77
77
|
200,
|
78
78
|
{ 'Content-Type': 'application/javascript' },
|
79
|
-
'{"
|
79
|
+
'{"origin": "127.0.0.1"}'
|
80
80
|
]
|
81
81
|
end
|
82
82
|
|
83
83
|
cli = client(stubs)
|
84
|
-
assert_equal '
|
84
|
+
assert_equal '127.0.0.1', cli.httpbingo('api', params: { abc: 123 })
|
85
85
|
|
86
86
|
# uncomment to raise Stubs::NotFound
|
87
|
-
# assert_equal '
|
87
|
+
# assert_equal '127.0.0.1', cli.httpbingo('api', params: { abc: 123, foo: 'Kappa' })
|
88
88
|
stubs.verify_stubbed_calls
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_non_default_params_encoder
|
92
92
|
stubs = Faraday::Adapter::Test::Stubs.new(strict_mode: true)
|
93
|
-
stubs.get('/
|
93
|
+
stubs.get('/api?a=x&a=y&a=z') do
|
94
94
|
[
|
95
95
|
200,
|
96
96
|
{ 'Content-Type': 'application/javascript' },
|
97
|
-
'{"
|
97
|
+
'{"origin": "127.0.0.1"}'
|
98
98
|
]
|
99
99
|
end
|
100
100
|
conn = Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) do |builder|
|
@@ -102,10 +102,10 @@ class ClientTest < Test::Unit::TestCase
|
|
102
102
|
end
|
103
103
|
|
104
104
|
cli = Client.new(conn)
|
105
|
-
assert_equal '
|
105
|
+
assert_equal '127.0.0.1', cli.httpbingo('api', params: { a: %w[x y z] })
|
106
106
|
|
107
107
|
# uncomment to raise Stubs::NotFound
|
108
|
-
# assert_equal '
|
108
|
+
# assert_equal '127.0.0.1', cli.httpbingo('api', params: { a: %w[x y] })
|
109
109
|
stubs.verify_stubbed_calls
|
110
110
|
end
|
111
111
|
|
data/lib/faraday/adapter/test.rb
CHANGED
@@ -55,6 +55,7 @@ module Faraday
|
|
55
55
|
@stack = {}
|
56
56
|
@consumed = {}
|
57
57
|
@strict_mode = strict_mode
|
58
|
+
@stubs_mutex = Monitor.new
|
58
59
|
yield(self) if block_given?
|
59
60
|
end
|
60
61
|
|
@@ -70,10 +71,13 @@ module Faraday
|
|
70
71
|
stack = @stack[request_method]
|
71
72
|
consumed = (@consumed[request_method] ||= [])
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
@stubs_mutex.synchronize do
|
75
|
+
stub, meta = matches?(stack, env)
|
76
|
+
if stub
|
77
|
+
removed = stack.delete(stub)
|
78
|
+
consumed << removed unless removed.nil?
|
79
|
+
return stub, meta
|
80
|
+
end
|
77
81
|
end
|
78
82
|
matches?(consumed, env)
|
79
83
|
end
|
data/lib/faraday/connection.rb
CHANGED
@@ -6,9 +6,9 @@ module Faraday
|
|
6
6
|
#
|
7
7
|
# @example
|
8
8
|
#
|
9
|
-
# conn = Faraday::Connection.new 'http://
|
9
|
+
# conn = Faraday::Connection.new 'http://httpbingo.org'
|
10
10
|
#
|
11
|
-
# # GET http://
|
11
|
+
# # GET http://httpbingo.org/nigiri
|
12
12
|
# conn.get 'nigiri'
|
13
13
|
# # => #<Faraday::Response>
|
14
14
|
#
|
@@ -349,11 +349,11 @@ module Faraday
|
|
349
349
|
# @example
|
350
350
|
#
|
351
351
|
# conn = Faraday::Connection.new { ... }
|
352
|
-
# conn.url_prefix = "https://
|
352
|
+
# conn.url_prefix = "https://httpbingo.org/api"
|
353
353
|
# conn.scheme # => https
|
354
354
|
# conn.path_prefix # => "/api"
|
355
355
|
#
|
356
|
-
# conn.get("nigiri?page=2") # accesses https://
|
356
|
+
# conn.get("nigiri?page=2") # accesses https://httpbingo.org/api/nigiri
|
357
357
|
def url_prefix=(url, encoder = nil)
|
358
358
|
uri = @url_prefix = Utils.URI(url)
|
359
359
|
self.path_prefix = uri.path
|
@@ -395,15 +395,15 @@ module Faraday
|
|
395
395
|
#
|
396
396
|
# @example
|
397
397
|
# conn = Faraday::Connection.new { ... }
|
398
|
-
# conn.url_prefix = "https://
|
398
|
+
# conn.url_prefix = "https://httpbingo.org/api?token=abc"
|
399
399
|
# conn.scheme # => https
|
400
400
|
# conn.path_prefix # => "/api"
|
401
401
|
#
|
402
402
|
# conn.build_url("nigiri?page=2")
|
403
|
-
# # => https://
|
403
|
+
# # => https://httpbingo.org/api/nigiri?token=abc&page=2
|
404
404
|
#
|
405
405
|
# conn.build_url("nigiri", page: 2)
|
406
|
-
# # => https://
|
406
|
+
# # => https://httpbingo.org/api/nigiri?token=abc&page=2
|
407
407
|
#
|
408
408
|
def build_url(url = nil, extra_params = nil)
|
409
409
|
uri = build_exclusive_url(url)
|
@@ -62,11 +62,17 @@ module Faraday
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def encode_array(parent, value)
|
65
|
-
|
66
|
-
return new_parent if value.empty?
|
65
|
+
return "#{parent}%5B%5D" if value.empty?
|
67
66
|
|
68
67
|
buffer = +''
|
69
|
-
value.
|
68
|
+
value.each_with_index do |val, index|
|
69
|
+
new_parent = if @array_indices
|
70
|
+
"#{parent}%5B#{index}%5D"
|
71
|
+
else
|
72
|
+
"#{parent}%5B%5D"
|
73
|
+
end
|
74
|
+
buffer << "#{encode_pair(new_parent, val)}&"
|
75
|
+
end
|
70
76
|
buffer.chop
|
71
77
|
end
|
72
78
|
end
|
@@ -161,7 +167,7 @@ module Faraday
|
|
161
167
|
# for your requests.
|
162
168
|
module NestedParamsEncoder
|
163
169
|
class << self
|
164
|
-
attr_accessor :sort_params
|
170
|
+
attr_accessor :sort_params, :array_indices
|
165
171
|
|
166
172
|
extend Forwardable
|
167
173
|
def_delegators :'Faraday::Utils', :escape, :unescape
|
@@ -169,6 +175,7 @@ module Faraday
|
|
169
175
|
|
170
176
|
# Useful default for OAuth and caching.
|
171
177
|
@sort_params = true
|
178
|
+
@array_indices = false
|
172
179
|
|
173
180
|
extend EncodeMethods
|
174
181
|
extend DecodeMethods
|
@@ -53,13 +53,31 @@ module Faraday
|
|
53
53
|
# Faraday::Middleware.lookup_middleware(:foo)
|
54
54
|
# # => Faraday::Whatever
|
55
55
|
def lookup_middleware(key)
|
56
|
-
|
56
|
+
load_middleware(key) ||
|
57
57
|
raise(Faraday::Error, "#{key.inspect} is not registered on #{self}")
|
58
58
|
end
|
59
59
|
|
60
|
+
private
|
61
|
+
|
60
62
|
def middleware_mutex(&block)
|
61
63
|
@middleware_mutex ||= Monitor.new
|
62
64
|
@middleware_mutex.synchronize(&block)
|
63
65
|
end
|
66
|
+
|
67
|
+
def load_middleware(key)
|
68
|
+
value = registered_middleware[key]
|
69
|
+
case value
|
70
|
+
when Module
|
71
|
+
value
|
72
|
+
when Symbol, String
|
73
|
+
middleware_mutex do
|
74
|
+
@registered_middleware[key] = const_get(value)
|
75
|
+
end
|
76
|
+
when Proc
|
77
|
+
middleware_mutex do
|
78
|
+
@registered_middleware[key] = value.call
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
64
82
|
end
|
65
83
|
end
|
data/lib/faraday/rack_builder.rb
CHANGED
@@ -8,7 +8,7 @@ module Faraday
|
|
8
8
|
# middleware stack (heavily inspired by Rack).
|
9
9
|
#
|
10
10
|
# @example
|
11
|
-
# Faraday::Connection.new(url: 'http://
|
11
|
+
# Faraday::Connection.new(url: 'http://httpbingo.org') do |builder|
|
12
12
|
# builder.request :url_encoded # Faraday::Request::UrlEncoded
|
13
13
|
# builder.adapter :net_http # Faraday::Adapter::NetHttp
|
14
14
|
# end
|
@@ -73,7 +73,7 @@ module Faraday
|
|
73
73
|
def build
|
74
74
|
raise_if_locked
|
75
75
|
block_given? ? yield(self) : request(:url_encoded)
|
76
|
-
adapter(Faraday.default_adapter) unless @adapter
|
76
|
+
adapter(Faraday.default_adapter, **Faraday.default_adapter_options) unless @adapter
|
77
77
|
end
|
78
78
|
|
79
79
|
def [](idx)
|
@@ -31,7 +31,9 @@ module Faraday
|
|
31
31
|
return unless process_request?(env)
|
32
32
|
|
33
33
|
env.request_headers[CONTENT_TYPE] ||= self.class.mime_type
|
34
|
-
|
34
|
+
return if env.body.respond_to?(:to_str) || env.body.respond_to?(:read)
|
35
|
+
|
36
|
+
yield(env.body)
|
35
37
|
end
|
36
38
|
|
37
39
|
# @param env [Faraday::Env]
|
data/lib/faraday/version.rb
CHANGED
data/lib/faraday.rb
CHANGED
@@ -47,13 +47,17 @@ module Faraday
|
|
47
47
|
|
48
48
|
# @overload default_adapter
|
49
49
|
# Gets the Symbol key identifying a default Adapter to use
|
50
|
-
# for the default {Faraday::Connection}. Defaults to `:
|
50
|
+
# for the default {Faraday::Connection}. Defaults to `:net_http`.
|
51
51
|
# @return [Symbol] the default adapter
|
52
52
|
# @overload default_adapter=(adapter)
|
53
53
|
# Updates default adapter while resetting {.default_connection}.
|
54
54
|
# @return [Symbol] the new default_adapter.
|
55
55
|
attr_reader :default_adapter
|
56
56
|
|
57
|
+
# Option for the default_adapter
|
58
|
+
# @return [Hash] default_adapter options
|
59
|
+
attr_accessor :default_adapter_options
|
60
|
+
|
57
61
|
# Documented below, see default_connection
|
58
62
|
attr_writer :default_connection
|
59
63
|
|
@@ -149,4 +153,5 @@ module Faraday
|
|
149
153
|
self.root_path = File.expand_path __dir__
|
150
154
|
self.lib_path = File.expand_path 'faraday', __dir__
|
151
155
|
self.default_adapter = :net_http
|
156
|
+
self.default_adapter_options = {}
|
152
157
|
end
|
@@ -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
|
|
@@ -165,8 +165,8 @@ RSpec.describe Faraday::Connection do
|
|
165
165
|
subject { conn.build_exclusive_url('sake.html') }
|
166
166
|
|
167
167
|
it 'uses connection host as default host' do
|
168
|
-
conn.host = '
|
169
|
-
expect(subject.host).to eq('
|
168
|
+
conn.host = 'httpbingo.org'
|
169
|
+
expect(subject.host).to eq('httpbingo.org')
|
170
170
|
expect(subject.scheme).to eq('http')
|
171
171
|
end
|
172
172
|
|
@@ -203,10 +203,10 @@ RSpec.describe Faraday::Connection do
|
|
203
203
|
end
|
204
204
|
|
205
205
|
context 'with complete url' do
|
206
|
-
subject { conn.build_exclusive_url('http://
|
206
|
+
subject { conn.build_exclusive_url('http://httpbingo.org/sake.html?a=1') }
|
207
207
|
|
208
208
|
it { expect(subject.scheme).to eq('http') }
|
209
|
-
it { expect(subject.host).to eq('
|
209
|
+
it { expect(subject.host).to eq('httpbingo.org') }
|
210
210
|
it { expect(subject.port).to eq(80) }
|
211
211
|
it { expect(subject.path).to eq('/sake.html') }
|
212
212
|
it { expect(subject.query).to eq('a=1') }
|
@@ -214,35 +214,35 @@ RSpec.describe Faraday::Connection do
|
|
214
214
|
|
215
215
|
it 'overrides connection port for absolute url' do
|
216
216
|
conn.port = 23
|
217
|
-
uri = conn.build_exclusive_url('http://
|
217
|
+
uri = conn.build_exclusive_url('http://httpbingo.org')
|
218
218
|
expect(uri.port).to eq(80)
|
219
219
|
end
|
220
220
|
|
221
221
|
it 'does not add ending slash given nil url' do
|
222
|
-
conn.url_prefix = 'http://
|
222
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
223
223
|
uri = conn.build_exclusive_url
|
224
224
|
expect(uri.path).to eq('/nigiri')
|
225
225
|
end
|
226
226
|
|
227
227
|
it 'does not add ending slash given empty url' do
|
228
|
-
conn.url_prefix = 'http://
|
228
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
229
229
|
uri = conn.build_exclusive_url('')
|
230
230
|
expect(uri.path).to eq('/nigiri')
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'does not use connection params' do
|
234
|
-
conn.url_prefix = 'http://
|
234
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
235
235
|
conn.params = { a: 1 }
|
236
|
-
expect(conn.build_exclusive_url.to_s).to eq('http://
|
236
|
+
expect(conn.build_exclusive_url.to_s).to eq('http://httpbingo.org/nigiri')
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'allows to provide params argument' do
|
240
|
-
conn.url_prefix = 'http://
|
240
|
+
conn.url_prefix = 'http://httpbingo.org/nigiri'
|
241
241
|
conn.params = { a: 1 }
|
242
242
|
params = Faraday::Utils::ParamsHash.new
|
243
243
|
params[:a] = 2
|
244
244
|
uri = conn.build_exclusive_url(nil, params)
|
245
|
-
expect(uri.to_s).to eq('http://
|
245
|
+
expect(uri.to_s).to eq('http://httpbingo.org/nigiri?a=2')
|
246
246
|
end
|
247
247
|
|
248
248
|
it 'handles uri instances' do
|
@@ -251,34 +251,34 @@ RSpec.describe Faraday::Connection do
|
|
251
251
|
end
|
252
252
|
|
253
253
|
it 'always returns new URI instance' do
|
254
|
-
conn.url_prefix = 'http://
|
254
|
+
conn.url_prefix = 'http://httpbingo.org'
|
255
255
|
uri1 = conn.build_exclusive_url(nil)
|
256
256
|
uri2 = conn.build_exclusive_url(nil)
|
257
257
|
expect(uri1).not_to equal(uri2)
|
258
258
|
end
|
259
259
|
|
260
260
|
context 'with url_prefixed connection' do
|
261
|
-
let(:url) { 'http://
|
261
|
+
let(:url) { 'http://httpbingo.org/get/' }
|
262
262
|
|
263
263
|
it 'parses url and changes scheme' do
|
264
264
|
conn.scheme = 'https'
|
265
265
|
uri = conn.build_exclusive_url('sake.html')
|
266
|
-
expect(uri.to_s).to eq('https://
|
266
|
+
expect(uri.to_s).to eq('https://httpbingo.org/get/sake.html')
|
267
267
|
end
|
268
268
|
|
269
269
|
it 'joins url to base with ending slash' do
|
270
270
|
uri = conn.build_exclusive_url('sake.html')
|
271
|
-
expect(uri.to_s).to eq('http://
|
271
|
+
expect(uri.to_s).to eq('http://httpbingo.org/get/sake.html')
|
272
272
|
end
|
273
273
|
|
274
274
|
it 'used default base with ending slash' do
|
275
275
|
uri = conn.build_exclusive_url
|
276
|
-
expect(uri.to_s).to eq('http://
|
276
|
+
expect(uri.to_s).to eq('http://httpbingo.org/get/')
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'overrides base' do
|
280
280
|
uri = conn.build_exclusive_url('/sake/')
|
281
|
-
expect(uri.to_s).to eq('http://
|
281
|
+
expect(uri.to_s).to eq('http://httpbingo.org/sake/')
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -307,22 +307,22 @@ RSpec.describe Faraday::Connection do
|
|
307
307
|
end
|
308
308
|
|
309
309
|
describe '#build_url' do
|
310
|
-
let(:url) { 'http://
|
310
|
+
let(:url) { 'http://httpbingo.org/nigiri' }
|
311
311
|
|
312
312
|
it 'uses params' do
|
313
313
|
conn.params = { a: 1, b: 1 }
|
314
|
-
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')
|
315
315
|
end
|
316
316
|
|
317
317
|
it 'merges params' do
|
318
318
|
conn.params = { a: 1, b: 1 }
|
319
319
|
url = conn.build_url(nil, b: 2, c: 3)
|
320
|
-
expect(url.to_s).to eq('http://
|
320
|
+
expect(url.to_s).to eq('http://httpbingo.org/nigiri?a=1&b=2&c=3')
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
324
324
|
describe '#build_request' do
|
325
|
-
let(:url) { 'https://
|
325
|
+
let(:url) { 'https://ahttpbingo.org/sake.html' }
|
326
326
|
let(:request) { conn.build_request(:get) }
|
327
327
|
|
328
328
|
before do
|
@@ -339,7 +339,7 @@ RSpec.describe Faraday::Connection do
|
|
339
339
|
describe '#to_env' do
|
340
340
|
subject { conn.build_request(:get).to_env(conn).url }
|
341
341
|
|
342
|
-
let(:url) { 'http://
|
342
|
+
let(:url) { 'http://httpbingo.org/sake.html' }
|
343
343
|
let(:options) { { params: @params } }
|
344
344
|
|
345
345
|
it 'parses url params into query' do
|
@@ -592,7 +592,7 @@ RSpec.describe Faraday::Connection do
|
|
592
592
|
describe '#dup' do
|
593
593
|
subject { conn.dup }
|
594
594
|
|
595
|
-
let(:url) { 'http://
|
595
|
+
let(:url) { 'http://httpbingo.org/foo' }
|
596
596
|
let(:options) do
|
597
597
|
{
|
598
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
|
@@ -102,6 +102,14 @@ RSpec.describe Faraday::NestedParamsEncoder do
|
|
102
102
|
Faraday::NestedParamsEncoder.sort_params = true
|
103
103
|
end
|
104
104
|
|
105
|
+
it 'encodes arrays indices when asked' do
|
106
|
+
params = { a: [0, 1, 2] }
|
107
|
+
expect(subject.encode(params)).to eq('a%5B%5D=0&a%5B%5D=1&a%5B%5D=2')
|
108
|
+
Faraday::NestedParamsEncoder.array_indices = true
|
109
|
+
expect(subject.encode(params)).to eq('a%5B0%5D=0&a%5B1%5D=1&a%5B2%5D=2')
|
110
|
+
Faraday::NestedParamsEncoder.array_indices = false
|
111
|
+
end
|
112
|
+
|
105
113
|
shared_examples 'a wrong decoding' do
|
106
114
|
it do
|
107
115
|
expect { subject.decode(query) }.to raise_error(TypeError) do |e|
|
@@ -110,18 +110,6 @@ RSpec.describe Faraday::RackBuilder do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
context 'with custom registered middleware' do
|
114
|
-
let(:conn) { Faraday::Connection.new {} }
|
115
|
-
|
116
|
-
after { Faraday::Middleware.unregister_middleware(:apple) }
|
117
|
-
|
118
|
-
it 'allows to register with constant' do
|
119
|
-
Faraday::Middleware.register_middleware(apple: Apple)
|
120
|
-
subject.use(:apple)
|
121
|
-
expect(subject.handlers).to eq([Apple])
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
113
|
context 'when having two handlers' do
|
126
114
|
let(:conn) { Faraday::Connection.new {} }
|
127
115
|
|
@@ -151,6 +139,33 @@ RSpec.describe Faraday::RackBuilder do
|
|
151
139
|
end
|
152
140
|
end
|
153
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
|
+
|
154
169
|
context 'when middleware is added with named arguments' do
|
155
170
|
let(:conn) { Faraday::Connection.new {} }
|
156
171
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'stringio'
|
4
|
+
|
3
5
|
RSpec.describe Faraday::Request::UrlEncoded do
|
4
6
|
let(:conn) do
|
5
7
|
Faraday.new do |b|
|
@@ -7,7 +9,11 @@ RSpec.describe Faraday::Request::UrlEncoded do
|
|
7
9
|
b.adapter :test do |stub|
|
8
10
|
stub.post('/echo') do |env|
|
9
11
|
posted_as = env[:request_headers]['Content-Type']
|
10
|
-
|
12
|
+
body = env[:body]
|
13
|
+
if body.respond_to?(:read)
|
14
|
+
body = body.read
|
15
|
+
end
|
16
|
+
[200, { 'Content-Type' => posted_as }, body]
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
@@ -67,6 +73,11 @@ RSpec.describe Faraday::Request::UrlEncoded do
|
|
67
73
|
expect(response.body).to eq('a%5Bb%5D%5Bc%5D%5B%5D=d')
|
68
74
|
end
|
69
75
|
|
76
|
+
it 'works with files' do
|
77
|
+
response = conn.post('/echo', StringIO.new('str=apple'))
|
78
|
+
expect(response.body).to eq('str=apple')
|
79
|
+
end
|
80
|
+
|
70
81
|
context 'customising default_space_encoding' do
|
71
82
|
around do |example|
|
72
83
|
Faraday::Utils.default_space_encoding = '%20'
|
@@ -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
|
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.0
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-05-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday-net_http
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- spec/faraday/adapter_spec.rb
|
92
92
|
- spec/faraday/connection_spec.rb
|
93
93
|
- spec/faraday/error_spec.rb
|
94
|
+
- spec/faraday/middleware_registry_spec.rb
|
94
95
|
- spec/faraday/middleware_spec.rb
|
95
96
|
- spec/faraday/options/env_spec.rb
|
96
97
|
- spec/faraday/options/options_spec.rb
|
@@ -124,7 +125,7 @@ licenses:
|
|
124
125
|
- MIT
|
125
126
|
metadata:
|
126
127
|
homepage_uri: https://lostisland.github.io/faraday
|
127
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.0
|
128
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.3.0
|
128
129
|
source_code_uri: https://github.com/lostisland/faraday
|
129
130
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
130
131
|
post_install_message:
|