faraday 1.7.0 → 2.0.0.alpha.pre.1
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 +111 -1
- data/README.md +16 -9
- data/examples/client_spec.rb +13 -0
- data/examples/client_test.rb +42 -3
- data/lib/faraday/adapter/test.rb +32 -43
- data/lib/faraday/adapter.rb +0 -5
- data/lib/faraday/connection.rb +8 -69
- data/lib/faraday/encoders/nested_params_encoder.rb +2 -2
- data/lib/faraday/error.rb +1 -0
- data/lib/faraday/file_part.rb +0 -6
- data/lib/faraday/logging/formatter.rb +1 -0
- data/lib/faraday/middleware.rb +0 -1
- data/lib/faraday/middleware_registry.rb +15 -79
- data/lib/faraday/options.rb +3 -3
- data/lib/faraday/rack_builder.rb +1 -1
- data/lib/faraday/request/authorization.rb +31 -38
- data/lib/faraday/request/instrumentation.rb +2 -0
- data/lib/faraday/request/json.rb +55 -0
- data/lib/faraday/request/multipart.rb +2 -0
- data/lib/faraday/request/retry.rb +3 -1
- data/lib/faraday/request/url_encoded.rb +2 -0
- data/lib/faraday/request.rb +13 -31
- data/lib/faraday/response/json.rb +54 -0
- data/lib/faraday/response/logger.rb +4 -4
- data/lib/faraday/response/raise_error.rb +9 -1
- data/lib/faraday/response.rb +8 -19
- data/lib/faraday/utils/headers.rb +1 -1
- data/lib/faraday/utils.rb +9 -4
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +6 -37
- data/spec/faraday/adapter/test_spec.rb +32 -0
- data/spec/faraday/connection_spec.rb +78 -51
- data/spec/faraday/options/env_spec.rb +2 -2
- data/spec/faraday/rack_builder_spec.rb +5 -43
- data/spec/faraday/request/authorization_spec.rb +15 -29
- data/spec/faraday/request/instrumentation_spec.rb +5 -7
- data/spec/faraday/request/json_spec.rb +111 -0
- data/spec/faraday/request/multipart_spec.rb +5 -5
- data/spec/faraday/request/retry_spec.rb +13 -1
- data/spec/faraday/request_spec.rb +0 -11
- data/spec/faraday/response/json_spec.rb +117 -0
- data/spec/faraday/response/raise_error_spec.rb +7 -4
- data/spec/faraday/utils_spec.rb +1 -1
- data/spec/support/fake_safe_buffer.rb +1 -1
- data/spec/support/shared_examples/request_method.rb +5 -5
- metadata +11 -134
- data/lib/faraday/adapter/typhoeus.rb +0 -15
- data/lib/faraday/autoload.rb +0 -87
- data/lib/faraday/dependency_loader.rb +0 -37
- data/lib/faraday/request/basic_authentication.rb +0 -20
- data/lib/faraday/request/token_authentication.rb +0 -20
- data/spec/faraday/adapter/em_http_spec.rb +0 -49
- data/spec/faraday/adapter/em_synchrony_spec.rb +0 -18
- data/spec/faraday/adapter/excon_spec.rb +0 -49
- data/spec/faraday/adapter/httpclient_spec.rb +0 -73
- data/spec/faraday/adapter/net_http_spec.rb +0 -64
- data/spec/faraday/adapter/patron_spec.rb +0 -18
- data/spec/faraday/adapter/rack_spec.rb +0 -8
- data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
- data/spec/faraday/response/middleware_spec.rb +0 -68
- data/spec/support/webmock_rack_app.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fafa8818a9063a9df90d878f7c6b79b0266f330fab9a9a271ac7b3d16e9bd8
|
4
|
+
data.tar.gz: ef16b014bc9ca58649557382c31817fba19c046029bb0c58c02a4b1a4654561e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec0843f0b2e4f37732bc6acd0fd2fb5417ce965c597e3385207ae2893bbe359cf037121712d0cbd7ce69371629bef9587b00b33036ae5bd087a23f1f5112cd96
|
7
|
+
data.tar.gz: 933b84778e644221a00d472ae0e9478672fcc4946a512eb2e03902cd8c082f56c2064fc37fb05ea4e3d904a9e2c7bb192c32b0ff22ce8b790f7b5edf08c490f1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,108 @@
|
|
1
1
|
# Faraday Changelog
|
2
2
|
|
3
|
+
## [v1.7.0](https://github.com/lostisland/faraday/releases/tag/v1.7.0) (2021-08-09)
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
* Add strict_mode to Test::Stubs (#1298, @yykamei)
|
8
|
+
|
9
|
+
## [v1.6.0](https://github.com/lostisland/faraday/releases/tag/v1.6.0) (2021-08-01)
|
10
|
+
|
11
|
+
### Misc
|
12
|
+
|
13
|
+
* Use external Rack adapter (#1296, @iMacTia)
|
14
|
+
|
15
|
+
## [v1.5.1](https://github.com/lostisland/faraday/releases/tag/v1.5.1) (2021-07-11)
|
16
|
+
|
17
|
+
### Fixes
|
18
|
+
|
19
|
+
* Fix JRuby incompatibility after moving out EM adapters (#1294, @ahorek)
|
20
|
+
|
21
|
+
### Documentation
|
22
|
+
|
23
|
+
* Update YARD to follow RackBuilder (#1292, @kachick)
|
24
|
+
|
25
|
+
## [v1.5.0](https://github.com/lostisland/faraday/releases/tag/v1.5.0) (2021-07-04)
|
26
|
+
|
27
|
+
### Misc
|
28
|
+
|
29
|
+
* Use external httpclient adapter (#1289, @iMacTia)
|
30
|
+
* Use external patron adapter (#1290, @iMacTia)
|
31
|
+
|
32
|
+
## [v1.4.3](https://github.com/lostisland/faraday/releases/tag/v1.4.3) (2021-06-24)
|
33
|
+
|
34
|
+
### Fixes
|
35
|
+
|
36
|
+
* Silence warning (#1286, @gurgeous)
|
37
|
+
* Always dup url_prefix in Connection#build_exclusive_url (#1288, @alexeyds)
|
38
|
+
|
39
|
+
## [v1.4.2](https://github.com/lostisland/faraday/releases/tag/v1.4.2) (2021-05-22)
|
40
|
+
|
41
|
+
### Fixes
|
42
|
+
* Add proxy setting when url_prefix is changed (#1276, @ci)
|
43
|
+
* Default proxy scheme to http:// if necessary, fixes #1282 (#1283, @gurgeous)
|
44
|
+
|
45
|
+
### Documentation
|
46
|
+
* Improve introduction page (#1273, @gurgeous)
|
47
|
+
* Docs: add more middleware examples (#1277, @gurgeous)
|
48
|
+
|
49
|
+
### Misc
|
50
|
+
* Use external `em_http` and `em_synchrony` adapters (#1274, @iMacTia)
|
51
|
+
|
52
|
+
## [v1.4.1](https://github.com/lostisland/faraday/releases/tag/v1.4.1) (2021-04-18)
|
53
|
+
|
54
|
+
### Fixes
|
55
|
+
|
56
|
+
* Fix dependencies from external adapter gems (#1269, @iMacTia)
|
57
|
+
|
58
|
+
## [v1.4.0](https://github.com/lostisland/faraday/releases/tag/v1.4.0) (2021-04-16)
|
59
|
+
|
60
|
+
### Highlights
|
61
|
+
|
62
|
+
With this release, we continue the work of gradually moving out adapters into their own gems 🎉
|
63
|
+
Thanks to @MikeRogers0 for helping the Faraday team in progressing with this quest 👏
|
64
|
+
|
65
|
+
And thanks to @olleolleolle efforts, Faraday is becoming more inclusive than ever 🤗
|
66
|
+
Faraday's `master` branch has been renamed into `main`, we have an official policy on inclusive language and even a rubocop plugin to check for non-inclusive words ❤️!
|
67
|
+
Checkout the "Misc" section below for more details 🙌 !
|
68
|
+
|
69
|
+
### Fixes
|
70
|
+
|
71
|
+
* Fix NoMethodError undefined method 'coverage' (#1255, @Maroo-b)
|
72
|
+
|
73
|
+
### Documentation
|
74
|
+
|
75
|
+
* Some docs on EventMachine adapters. (#1232, @damau)
|
76
|
+
* CONTRIBUTING: Fix grammar and layout (#1261, @olleolleolle)
|
77
|
+
|
78
|
+
### Misc
|
79
|
+
|
80
|
+
* Replacing Net::HTTP::Persistent with faraday-net_http_persistent (#1250, @MikeRogers0)
|
81
|
+
* CI: Configure the regenerated Coveralls token (#1256, @olleolleolle)
|
82
|
+
* Replace Excon adapter with Faraday::Excon gem, and fix autoloading issue with Faraday::NetHttpPersistent (#1257, @iMacTia)
|
83
|
+
* Drop CodeClimate (#1259, @olleolleolle)
|
84
|
+
* CI: Rename default branch to main (#1263, @olleolleolle)
|
85
|
+
* Drop RDoc support file .document (#1264, @olleolleolle, @iMacTia)
|
86
|
+
* CONTRIBUTING: add a policy on inclusive language (#1262, @olleolleolle)
|
87
|
+
* Add rubocop-inclusivity (#1267, @olleolleolle, @iMacTia)
|
88
|
+
|
89
|
+
## [v1.3.1](https://github.com/lostisland/faraday/releases/tag/v1.3.1) (2021-04-16)
|
90
|
+
|
91
|
+
### Fixes
|
92
|
+
|
93
|
+
* Escape colon in path segment (#1237, @yarafan)
|
94
|
+
* Handle IPv6 address String on Faraday::Connection#proxy_from_env (#1252, @cosmo0920)
|
95
|
+
|
96
|
+
### Documentation
|
97
|
+
|
98
|
+
* Fix broken Rubydoc.info links (#1236, @nickcampbell18)
|
99
|
+
* Add httpx to list of external adapters (#1246, @HoneyryderChuck)
|
100
|
+
|
101
|
+
### Misc
|
102
|
+
|
103
|
+
* Refactor CI to remove duplicated line (#1230, @tricknotes)
|
104
|
+
* Gemspec: Pick a good ruby2_keywords release (#1241, @olleolleolle)
|
105
|
+
|
3
106
|
## [v1.3.0](https://github.com/lostisland/faraday/releases/tag/v1.3.0) (2020-12-31)
|
4
107
|
|
5
108
|
### Highlights
|
@@ -104,7 +207,7 @@ Many thanks to the Faraday Team, @JanDintel and everyone who attended the [ROSS
|
|
104
207
|
* Website: add search bar (#1116)
|
105
208
|
* Fix request/response mix-up in docs text (#1132)
|
106
209
|
|
107
|
-
## v1.0
|
210
|
+
## [v1.0](https://github.com/lostisland/faraday/releases/tag/v1.0.0) (2020-01-22)
|
108
211
|
|
109
212
|
Features:
|
110
213
|
|
@@ -148,6 +251,13 @@ Misc:
|
|
148
251
|
* Describe clearing cached stubs #1045 (@viraptor)
|
149
252
|
* Add project metadata to the gemspec #1046 (@orien)
|
150
253
|
|
254
|
+
## v0.17.4
|
255
|
+
|
256
|
+
Fixes:
|
257
|
+
|
258
|
+
* NetHttp adapter: wrap Errno::EADDRNOTAVAIL (#1114, @embs)
|
259
|
+
* Fix === for subclasses of deprecated classes (#1243, @mervync)
|
260
|
+
|
151
261
|
## v0.17.3
|
152
262
|
|
153
263
|
Fixes:
|
data/README.md
CHANGED
@@ -2,12 +2,18 @@
|
|
2
2
|
|
3
3
|
[](https://rubygems.org/gems/faraday)
|
4
4
|
[](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
|
5
|
-
[](https://github.com/lostisland/faraday/discussions)
|
6
6
|
|
7
7
|
|
8
|
-
Faraday is an HTTP client library that provides a common interface over many
|
9
|
-
adapters (such as Net::HTTP) and embraces the concept of Rack middleware when
|
10
|
-
|
8
|
+
Faraday is an HTTP client library abstraction layer that provides a common interface over many
|
9
|
+
adapters (such as Net::HTTP) and embraces the concept of Rack middleware when processing the request/response cycle.
|
10
|
+
You probably don't want to use Faraday directly in your project, as it will lack an actual client library to perform
|
11
|
+
requests. Instead, you probably want to have a look at [Awesome Faraday][awesome] for a list of available adapters.
|
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).
|
11
17
|
|
12
18
|
## Getting Started
|
13
19
|
|
@@ -16,10 +22,10 @@ Need more details? See the [Faraday API Documentation][apidoc] to see how it wor
|
|
16
22
|
|
17
23
|
## Supported Ruby versions
|
18
24
|
|
19
|
-
This library aims to support and is [tested against][actions] the
|
20
|
-
implementations
|
21
|
-
|
22
|
-
|
25
|
+
This library aims to support and is [tested against][actions] the currently officially supported Ruby
|
26
|
+
implementations. This means that, even without a major release, we could add or drop support for Ruby versions,
|
27
|
+
following their [EOL](https://endoflife.date/ruby).
|
28
|
+
Currently that means we support Ruby 2.6+
|
23
29
|
|
24
30
|
If something doesn't work on one of these Ruby versions, it's a bug.
|
25
31
|
|
@@ -41,8 +47,9 @@ Open the issues page and check for the `help wanted` label!
|
|
41
47
|
But before you start coding, please read our [Contributing Guide][contributing]
|
42
48
|
|
43
49
|
## Copyright
|
44
|
-
© 2009 -
|
50
|
+
© 2009 - 2021, the [Faraday Team][faraday_team]. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
|
45
51
|
|
52
|
+
[awesome]: https://github.com/lostisland/awesome-faraday/#adapters
|
46
53
|
[website]: https://lostisland.github.io/faraday
|
47
54
|
[faraday_team]: https://lostisland.github.io/faraday/team
|
48
55
|
[contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
|
data/examples/client_spec.rb
CHANGED
@@ -81,4 +81,17 @@ RSpec.describe Client do
|
|
81
81
|
stubs.verify_stubbed_calls
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
context 'When the Faraday connection is configured with FlatParamsEncoder' do
|
86
|
+
let(:conn) { Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) { |b| b.adapter(:test, stubs) } }
|
87
|
+
|
88
|
+
it 'handles the same multiple URL parameters' do
|
89
|
+
stubs.get('/ebi?a=x&a=y&a=z') { [200, { 'Content-Type' => 'application/json' }, '{"name": "shrimp"}'] }
|
90
|
+
|
91
|
+
# uncomment to raise Stubs::NotFound
|
92
|
+
# expect(client.sushi('ebi', params: { a: %w[x y] })).to eq('shrimp')
|
93
|
+
expect(client.sushi('ebi', params: { a: %w[x y z] })).to eq('shrimp')
|
94
|
+
stubs.verify_stubbed_calls
|
95
|
+
end
|
96
|
+
end
|
84
97
|
end
|
data/examples/client_test.rb
CHANGED
@@ -13,8 +13,8 @@ class Client
|
|
13
13
|
@conn = conn
|
14
14
|
end
|
15
15
|
|
16
|
-
def sushi(jname)
|
17
|
-
res = @conn.get("/#{jname}")
|
16
|
+
def sushi(jname, params: {})
|
17
|
+
res = @conn.get("/#{jname}", params)
|
18
18
|
data = JSON.parse(res.body)
|
19
19
|
data['name']
|
20
20
|
end
|
@@ -42,7 +42,7 @@ class ClientTest < Test::Unit::TestCase
|
|
42
42
|
stubs.verify_stubbed_calls
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def test_sushi_not_found
|
46
46
|
stubs = Faraday::Adapter::Test::Stubs.new
|
47
47
|
stubs.get('/ebi') do
|
48
48
|
[
|
@@ -70,6 +70,45 @@ class ClientTest < Test::Unit::TestCase
|
|
70
70
|
stubs.verify_stubbed_calls
|
71
71
|
end
|
72
72
|
|
73
|
+
def test_strict_mode
|
74
|
+
stubs = Faraday::Adapter::Test::Stubs.new(strict_mode: true)
|
75
|
+
stubs.get('/ebi?abc=123') do
|
76
|
+
[
|
77
|
+
200,
|
78
|
+
{ 'Content-Type': 'application/javascript' },
|
79
|
+
'{"name": "shrimp"}'
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
cli = client(stubs)
|
84
|
+
assert_equal 'shrimp', cli.sushi('ebi', params: { abc: 123 })
|
85
|
+
|
86
|
+
# uncomment to raise Stubs::NotFound
|
87
|
+
# assert_equal 'shrimp', cli.sushi('ebi', params: { abc: 123, foo: 'Kappa' })
|
88
|
+
stubs.verify_stubbed_calls
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_non_default_params_encoder
|
92
|
+
stubs = Faraday::Adapter::Test::Stubs.new(strict_mode: true)
|
93
|
+
stubs.get('/ebi?a=x&a=y&a=z') do
|
94
|
+
[
|
95
|
+
200,
|
96
|
+
{ 'Content-Type': 'application/javascript' },
|
97
|
+
'{"name": "shrimp"}'
|
98
|
+
]
|
99
|
+
end
|
100
|
+
conn = Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) do |builder|
|
101
|
+
builder.adapter :test, stubs
|
102
|
+
end
|
103
|
+
|
104
|
+
cli = Client.new(conn)
|
105
|
+
assert_equal 'shrimp', cli.sushi('ebi', params: { a: %w[x y z] })
|
106
|
+
|
107
|
+
# uncomment to raise Stubs::NotFound
|
108
|
+
# assert_equal 'shrimp', cli.sushi('ebi', params: { a: %w[x y] })
|
109
|
+
stubs.verify_stubbed_calls
|
110
|
+
end
|
111
|
+
|
73
112
|
def client(stubs)
|
74
113
|
conn = Faraday.new do |builder|
|
75
114
|
builder.adapter :test, stubs
|
data/lib/faraday/adapter/test.rb
CHANGED
@@ -62,18 +62,20 @@ module Faraday
|
|
62
62
|
@stack.empty?
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
# @param env [Faraday::Env]
|
66
|
+
def match(env)
|
67
|
+
request_method = env[:method]
|
66
68
|
return false unless @stack.key?(request_method)
|
67
69
|
|
68
70
|
stack = @stack[request_method]
|
69
71
|
consumed = (@consumed[request_method] ||= [])
|
70
72
|
|
71
|
-
stub, meta = matches?(stack,
|
73
|
+
stub, meta = matches?(stack, env)
|
72
74
|
if stub
|
73
75
|
consumed << stack.delete(stub)
|
74
76
|
return stub, meta
|
75
77
|
end
|
76
|
-
matches?(consumed,
|
78
|
+
matches?(consumed, env)
|
77
79
|
end
|
78
80
|
|
79
81
|
def get(path, headers = {}, &block)
|
@@ -142,15 +144,18 @@ module Faraday
|
|
142
144
|
Faraday::Utils.URI(path).host
|
143
145
|
]
|
144
146
|
end
|
145
|
-
|
147
|
+
path, query = normalized_path.respond_to?(:split) ? normalized_path.split('?') : normalized_path
|
146
148
|
headers = Utils::Headers.new(headers)
|
147
|
-
|
149
|
+
|
150
|
+
stub = Stub.new(host, path, query, headers, body, @strict_mode, block)
|
148
151
|
(@stack[request_method] ||= []) << stub
|
149
152
|
end
|
150
153
|
|
151
|
-
|
154
|
+
# @param stack [Hash]
|
155
|
+
# @param env [Faraday::Env]
|
156
|
+
def matches?(stack, env)
|
152
157
|
stack.each do |stub|
|
153
|
-
match_result, meta = stub.matches?(
|
158
|
+
match_result, meta = stub.matches?(env)
|
154
159
|
return stub, meta if match_result
|
155
160
|
end
|
156
161
|
nil
|
@@ -158,35 +163,20 @@ module Faraday
|
|
158
163
|
end
|
159
164
|
|
160
165
|
# Stub request
|
161
|
-
# rubocop:disable Style/StructInheritance
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
Faraday::Utils.parse_nested_query(query)
|
169
|
-
else
|
170
|
-
{}
|
171
|
-
end
|
172
|
-
|
173
|
-
super(host, path, params, headers, body, strict_mode, block)
|
174
|
-
end
|
166
|
+
class Stub < Struct.new(:host, :path, :query, :headers, :body, :strict_mode, :block) # rubocop:disable Style/StructInheritance
|
167
|
+
# @param env [Faraday::Env]
|
168
|
+
def matches?(env)
|
169
|
+
request_host = env[:url].host
|
170
|
+
request_path = Faraday::Utils.normalize_path(env[:url].path)
|
171
|
+
request_headers = env.request_headers
|
172
|
+
request_body = env[:body]
|
175
173
|
|
176
|
-
def matches?(request_host, request_uri, request_headers, request_body)
|
177
|
-
request_path, request_query = request_uri.split('?')
|
178
|
-
request_params =
|
179
|
-
if request_query
|
180
|
-
Faraday::Utils.parse_nested_query(request_query)
|
181
|
-
else
|
182
|
-
{}
|
183
|
-
end
|
184
174
|
# meta is a hash used as carrier
|
185
175
|
# that will be yielded to consumer block
|
186
176
|
meta = {}
|
187
177
|
[(host.nil? || host == request_host) &&
|
188
178
|
path_match?(request_path, meta) &&
|
189
|
-
params_match?(
|
179
|
+
params_match?(env) &&
|
190
180
|
(body.to_s.size.zero? || request_body == body) &&
|
191
181
|
headers_match?(request_headers), meta]
|
192
182
|
end
|
@@ -199,7 +189,11 @@ module Faraday
|
|
199
189
|
end
|
200
190
|
end
|
201
191
|
|
202
|
-
|
192
|
+
# @param env [Faraday::Env]
|
193
|
+
def params_match?(env)
|
194
|
+
request_params = env[:params]
|
195
|
+
params = env.params_encoder.decode(query) || {}
|
196
|
+
|
203
197
|
if strict_mode
|
204
198
|
return Set.new(params) == Set.new(request_params)
|
205
199
|
end
|
@@ -239,26 +233,19 @@ module Faraday
|
|
239
233
|
yield(stubs)
|
240
234
|
end
|
241
235
|
|
236
|
+
# @param env [Faraday::Env]
|
242
237
|
def call(env)
|
243
238
|
super
|
244
|
-
host = env[:url].host
|
245
|
-
normalized_path = Faraday::Utils.normalize_path(env[:url])
|
246
|
-
params_encoder = env.request.params_encoder ||
|
247
|
-
Faraday::Utils.default_params_encoder
|
248
239
|
|
249
|
-
|
250
|
-
|
240
|
+
env.request.params_encoder ||= Faraday::Utils.default_params_encoder
|
241
|
+
env[:params] = env.params_encoder.decode(env[:url].query) || {}
|
242
|
+
stub, meta = stubs.match(env)
|
251
243
|
|
252
244
|
unless stub
|
253
245
|
raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\
|
254
|
-
"#{
|
246
|
+
"#{env[:url]} #{env[:body]}"
|
255
247
|
end
|
256
248
|
|
257
|
-
env[:params] = if (query = env[:url].query)
|
258
|
-
params_encoder.decode(query)
|
259
|
-
else
|
260
|
-
{}
|
261
|
-
end
|
262
249
|
block_arity = stub.block.arity
|
263
250
|
status, headers, body =
|
264
251
|
if block_arity >= 0
|
@@ -273,3 +260,5 @@ module Faraday
|
|
273
260
|
end
|
274
261
|
end
|
275
262
|
end
|
263
|
+
|
264
|
+
Faraday::Adapter.register_middleware(test: Faraday::Adapter::Test)
|
data/lib/faraday/adapter.rb
CHANGED
@@ -5,14 +5,9 @@ module Faraday
|
|
5
5
|
# responsible for fulfilling a Faraday request.
|
6
6
|
class Adapter
|
7
7
|
extend MiddlewareRegistry
|
8
|
-
extend DependencyLoader
|
9
8
|
|
10
9
|
CONTENT_LENGTH = 'Content-Length'
|
11
10
|
|
12
|
-
register_middleware File.expand_path('adapter', __dir__),
|
13
|
-
test: [:Test, 'test'],
|
14
|
-
typhoeus: [:Typhoeus, 'typhoeus']
|
15
|
-
|
16
11
|
# This module marks an Adapter as supporting parallel requests.
|
17
12
|
module Parallelism
|
18
13
|
attr_writer :supports_parallel
|
data/lib/faraday/connection.rb
CHANGED
@@ -283,62 +283,6 @@ module Faraday
|
|
283
283
|
RUBY
|
284
284
|
end
|
285
285
|
|
286
|
-
# Sets up the Authorization header with these credentials, encoded
|
287
|
-
# with base64.
|
288
|
-
#
|
289
|
-
# @param login [String] The authentication login.
|
290
|
-
# @param pass [String] The authentication password.
|
291
|
-
#
|
292
|
-
# @example
|
293
|
-
#
|
294
|
-
# conn.basic_auth 'Aladdin', 'open sesame'
|
295
|
-
# conn.headers['Authorization']
|
296
|
-
# # => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
|
297
|
-
#
|
298
|
-
# @return [void]
|
299
|
-
def basic_auth(login, pass)
|
300
|
-
set_authorization_header(:basic_auth, login, pass)
|
301
|
-
end
|
302
|
-
|
303
|
-
# Sets up the Authorization header with the given token.
|
304
|
-
#
|
305
|
-
# @param token [String]
|
306
|
-
# @param options [Hash] extra token options.
|
307
|
-
#
|
308
|
-
# @example
|
309
|
-
#
|
310
|
-
# conn.token_auth 'abcdef', foo: 'bar'
|
311
|
-
# conn.headers['Authorization']
|
312
|
-
# # => "Token token=\"abcdef\",
|
313
|
-
# foo=\"bar\""
|
314
|
-
#
|
315
|
-
# @return [void]
|
316
|
-
def token_auth(token, options = nil)
|
317
|
-
set_authorization_header(:token_auth, token, options)
|
318
|
-
end
|
319
|
-
|
320
|
-
# Sets up a custom Authorization header.
|
321
|
-
#
|
322
|
-
# @param type [String] authorization type
|
323
|
-
# @param token [String, Hash] token. A String value is taken literally, and
|
324
|
-
# a Hash is encoded into comma-separated key/value pairs.
|
325
|
-
#
|
326
|
-
# @example
|
327
|
-
#
|
328
|
-
# conn.authorization :Bearer, 'mF_9.B5f-4.1JqM'
|
329
|
-
# conn.headers['Authorization']
|
330
|
-
# # => "Bearer mF_9.B5f-4.1JqM"
|
331
|
-
#
|
332
|
-
# conn.authorization :Token, token: 'abcdef', foo: 'bar'
|
333
|
-
# conn.headers['Authorization']
|
334
|
-
# # => "Token token=\"abcdef\",
|
335
|
-
# foo=\"bar\""
|
336
|
-
#
|
337
|
-
# @return [void]
|
338
|
-
def authorization(type, token)
|
339
|
-
set_authorization_header(:authorization, type, token)
|
340
|
-
end
|
341
|
-
|
342
286
|
# Check if the adapter is parallel-capable.
|
343
287
|
#
|
344
288
|
# @yield if the adapter isn't parallel-capable, or if no adapter is set yet.
|
@@ -418,13 +362,18 @@ module Faraday
|
|
418
362
|
uri.query = nil
|
419
363
|
|
420
364
|
with_uri_credentials(uri) do |user, password|
|
421
|
-
|
365
|
+
set_basic_auth(user, password)
|
422
366
|
uri.user = uri.password = nil
|
423
367
|
end
|
424
368
|
|
425
369
|
@proxy = proxy_from_env(url) unless @manual_proxy
|
426
370
|
end
|
427
371
|
|
372
|
+
def set_basic_auth(user, password)
|
373
|
+
header = Faraday::Utils.basic_header_from(user, password)
|
374
|
+
headers[Faraday::Request::Authorization::KEY] = header
|
375
|
+
end
|
376
|
+
|
428
377
|
# Sets the path prefix and ensures that it always has a leading
|
429
378
|
# slash.
|
430
379
|
#
|
@@ -525,14 +474,12 @@ module Faraday
|
|
525
474
|
if url && base.path && base.path !~ %r{/$}
|
526
475
|
base.path = "#{base.path}/" # ensure trailing slash
|
527
476
|
end
|
528
|
-
url = url
|
477
|
+
url = url.to_s.gsub(':', '%3A') if url && URI.parse(url.to_s).opaque
|
529
478
|
uri = url ? base + url : base
|
530
479
|
if params
|
531
480
|
uri.query = params.to_query(params_encoder || options.params_encoder)
|
532
481
|
end
|
533
|
-
# rubocop:disable Style/SafeNavigation
|
534
482
|
uri.query = nil if uri.query && uri.query.empty?
|
535
|
-
# rubocop:enable Style/SafeNavigation
|
536
483
|
uri
|
537
484
|
end
|
538
485
|
|
@@ -564,14 +511,6 @@ module Faraday
|
|
564
511
|
yield(Utils.unescape(uri.user), Utils.unescape(uri.password))
|
565
512
|
end
|
566
513
|
|
567
|
-
def set_authorization_header(header_type, *args)
|
568
|
-
header = Faraday::Request
|
569
|
-
.lookup_middleware(header_type)
|
570
|
-
.header(*args)
|
571
|
-
|
572
|
-
headers[Faraday::Request::Authorization::KEY] = header
|
573
|
-
end
|
574
|
-
|
575
514
|
def proxy_from_env(url)
|
576
515
|
return if Faraday.ignore_env_proxy
|
577
516
|
|
@@ -616,7 +555,7 @@ module Faraday
|
|
616
555
|
end
|
617
556
|
|
618
557
|
def support_parallel?(adapter)
|
619
|
-
adapter
|
558
|
+
adapter.respond_to?(:supports_parallel?) && adapter&.supports_parallel?
|
620
559
|
end
|
621
560
|
end
|
622
561
|
end
|
@@ -102,7 +102,7 @@ module Faraday
|
|
102
102
|
subkeys = key.scan(SUBKEYS_REGEX)
|
103
103
|
subkeys.each_with_index do |subkey, i|
|
104
104
|
is_array = subkey =~ /[\[\]]+\Z/
|
105
|
-
subkey =
|
105
|
+
subkey = Regexp.last_match.pre_match if is_array
|
106
106
|
last_subkey = i == subkeys.length - 1
|
107
107
|
|
108
108
|
context = prepare_context(context, subkey, is_array, last_subkey)
|
@@ -124,7 +124,7 @@ module Faraday
|
|
124
124
|
value_type = is_array ? Array : Hash
|
125
125
|
if context[subkey] && !context[subkey].is_a?(value_type)
|
126
126
|
raise TypeError, "expected #{value_type.name} " \
|
127
|
-
|
127
|
+
"(got #{context[subkey].class.name}) for param `#{subkey}'"
|
128
128
|
end
|
129
129
|
|
130
130
|
context[subkey] ||= value_type.new
|
data/lib/faraday/error.rb
CHANGED
@@ -52,6 +52,7 @@ module Faraday
|
|
52
52
|
# :body - Optional string HTTP response body.
|
53
53
|
# :request - Hash
|
54
54
|
# :method - Symbol with the request HTTP method.
|
55
|
+
# :url - URI object with the url requested.
|
55
56
|
# :url_path - String with the url path requested.
|
56
57
|
# :params - String key/value hash of query params
|
57
58
|
# present in the request.
|
data/lib/faraday/file_part.rb
CHANGED
@@ -52,12 +52,6 @@ module Faraday
|
|
52
52
|
# @return [IO]
|
53
53
|
FilePart = ::UploadIO
|
54
54
|
|
55
|
-
# Multipart value used to POST a file.
|
56
|
-
#
|
57
|
-
# @deprecated Use FilePart instead of this class. It behaves identically, with
|
58
|
-
# a matching name to ParamPart.
|
59
|
-
UploadIO = ::UploadIO
|
60
|
-
|
61
55
|
Parts = ::Parts
|
62
56
|
|
63
57
|
# Similar to, but not compatible with CompositeReadIO provided by the
|