faraday 1.1.0 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +104 -0
  3. data/README.md +1 -2
  4. data/examples/client_spec.rb +34 -2
  5. data/examples/client_test.rb +41 -2
  6. data/lib/faraday/adapter/test.rb +59 -43
  7. data/lib/faraday/adapter.rb +1 -12
  8. data/lib/faraday/autoload.rb +1 -9
  9. data/lib/faraday/connection.rb +34 -6
  10. data/lib/faraday/deprecate.rb +110 -0
  11. data/lib/faraday/error.rb +12 -6
  12. data/lib/faraday/methods.rb +6 -0
  13. data/lib/faraday/middleware.rb +14 -4
  14. data/lib/faraday/options/proxy_options.rb +4 -0
  15. data/lib/faraday/request/authorization.rb +14 -7
  16. data/lib/faraday/request/json.rb +55 -0
  17. data/lib/faraday/request.rb +10 -12
  18. data/lib/faraday/response/json.rb +54 -0
  19. data/lib/faraday/response/logger.rb +2 -4
  20. data/lib/faraday/response.rb +3 -7
  21. data/lib/faraday/version.rb +5 -0
  22. data/lib/faraday.rb +67 -40
  23. data/spec/faraday/adapter/em_http_spec.rb +39 -37
  24. data/spec/faraday/adapter/em_synchrony_spec.rb +11 -9
  25. data/spec/faraday/adapter/test_spec.rb +117 -0
  26. data/spec/faraday/connection_spec.rb +45 -0
  27. data/spec/faraday/deprecate_spec.rb +147 -0
  28. data/spec/faraday/error_spec.rb +15 -0
  29. data/spec/faraday/middleware_spec.rb +32 -6
  30. data/spec/faraday/options/proxy_options_spec.rb +7 -0
  31. data/spec/faraday/request/authorization_spec.rb +8 -0
  32. data/spec/faraday/request/json_spec.rb +111 -0
  33. data/spec/faraday/request_spec.rb +1 -1
  34. data/spec/faraday/response/json_spec.rb +119 -0
  35. data/spec/faraday/response/raise_error_spec.rb +30 -0
  36. data/spec/spec_helper.rb +2 -0
  37. data/spec/support/shared_examples/adapter.rb +2 -1
  38. data/spec/support/shared_examples/request_method.rb +36 -8
  39. metadata +143 -32
  40. data/lib/faraday/adapter/em_http.rb +0 -286
  41. data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
  42. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
  43. data/lib/faraday/adapter/em_synchrony.rb +0 -150
  44. data/lib/faraday/adapter/excon.rb +0 -124
  45. data/lib/faraday/adapter/httpclient.rb +0 -152
  46. data/lib/faraday/adapter/net_http.rb +0 -219
  47. data/lib/faraday/adapter/net_http_persistent.rb +0 -91
  48. data/lib/faraday/adapter/patron.rb +0 -132
  49. data/lib/faraday/adapter/rack.rb +0 -75
  50. data/lib/faraday/file_part.rb +0 -128
  51. data/lib/faraday/param_part.rb +0 -53
  52. data/lib/faraday/request/multipart.rb +0 -106
  53. data/lib/faraday/request/retry.rb +0 -239
  54. data/spec/faraday/adapter/net_http_persistent_spec.rb +0 -57
  55. data/spec/faraday/request/multipart_spec.rb +0 -302
  56. data/spec/faraday/request/retry_spec.rb +0 -242
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47236f354f9fda55254c8bd2b9e3552de12e8894fcecea0035ffbeb3ccc46b9c
4
- data.tar.gz: f6eb36d3da02314fe799368c1ff4c17c5841f0badd18c5a89772e00bae43065c
3
+ metadata.gz: 5a35b8ef069416d74f46cbe1f9b14b9d28e8b141bed4143d2c97ac137b766f18
4
+ data.tar.gz: cdbb3768e4aa6d316e2216ec7fdf2a93b5141abe83dd82b3ffa522002b01523c
5
5
  SHA512:
6
- metadata.gz: 300153861873b2a5b3a3a9f552c47a2b70dd083ffd5478d8eca2c4c2005e5a74d09d962b51fb9a780ea90bb1ac87bdfa902639e86b2147d5b4d4374791789bd1
7
- data.tar.gz: 3628d85508cdd669111ae6175b6b5a191380d0d405f345612f6342e487aec0f3cc9d2e1726a2cdde7d82ee86fae82aa41f4a62ea330343598383ae3f644b5a85
6
+ metadata.gz: 743727fca5013eb1bd1f005c334d171fc59a5cb56687395b3d14a48911ee4b7fef5da00e64ac6dbe15b75cc76edcb26d400b4d748e9676d9cdb12e8d2d8ee7b7
7
+ data.tar.gz: 203527c8adc2828334b74e97a33041ed9127548b91905d15331ff627c5f20d679c3d2ccd0b3102c0de35e011c5f15f2bac50b8aa4eccaeafaf1551611ca020e1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,109 @@
1
1
  # Faraday Changelog
2
2
 
3
+ ## [v1.3.0](https://github.com/lostisland/faraday/releases/tag/v1.3.0) (2020-12-31)
4
+
5
+ ### Highlights
6
+ Faraday v1.3.0 is the first release to officially support Ruby 3.0 in the CI pipeline 🎉 🍾!
7
+
8
+ 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) 🎊!
9
+ 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!
10
+
11
+ This is a huge step towards are Faraday v2.0 objective of pushing adapters and middleware into separate gems.
12
+ Many thanks to the Faraday Team, @JanDintel and everyone who attended the [ROSS Conf remote event](https://www.rossconf.io/event/remote/)
13
+
14
+ ### Features
15
+
16
+ * Improves consistency with Faraday::Error and Faraday::RaiseError (#1229, @qsona, @iMacTia)
17
+
18
+ ### Fixes
19
+
20
+ * Don't assign to global ::Timer (#1227, @bpo)
21
+
22
+ ### Documentation
23
+
24
+ * CHANGELOG: add releases after 1.0 (#1225, @olleolleolle)
25
+ * Improves retry middleware documentation. (#1228, @iMacTia)
26
+
27
+ ### Misc
28
+
29
+ * Move out Net::HTTP adapter (#1222, @JanDintel, @iMacTia)
30
+ * Adds Ruby 3.0 to CI Matrix (#1226, @iMacTia)
31
+
32
+
33
+ ## [v1.2.0](https://github.com/lostisland/faraday/releases/tag/v1.2.0) (2020-12-23)
34
+
35
+ ### Features
36
+
37
+ * Introduces `on_request` and `on_complete` methods in `Faraday::Middleware`. (#1194, @iMacTia)
38
+
39
+ ### Fixes
40
+
41
+ * Require 'date' to avoid retry exception (#1206, @rustygeldmacher)
42
+ * Fix rdebug recursion issue (#1205, @native-api)
43
+ * Update call to `em_http_ssl_patch` (#1202, @kylekeesling)
44
+ * `EmHttp` adapter: drop superfluous loaded? check (#1213, @olleolleolle)
45
+ * Avoid 1 use of keyword hackery (#1211, @grosser)
46
+ * Fix #1219 `Net::HTTP` still uses env proxy (#1221, @iMacTia)
47
+
48
+ ### Documentation
49
+
50
+ * Add comment in gemspec to explain exposure of `examples` and `spec` folders. (#1192, @iMacTia)
51
+ * Adapters, how to create them (#1193, @olleolleolle)
52
+ * Update documentation on using the logger (#1196, @tijmenb)
53
+ * Adjust the retry documentation and spec to align with implementation (#1198, @nbeyer)
54
+
55
+ ### Misc
56
+
57
+ * Test against ruby head (#1208, @grosser)
58
+
59
+ ## [v1.1.0](https://github.com/lostisland/faraday/releases/tag/v1.1.0) (2020-10-17)
60
+
61
+ ### Features
62
+
63
+ * Makes parameters sorting configurable (#1162 @wishdev)
64
+ * Introduces `flat_encode` option for multipart adapter. (#1163 @iMacTia)
65
+ * Include request info in exceptions raised by RaiseError Middleware (#1181 @SandroDamilano)
66
+
67
+ ### Fixes
68
+
69
+ * Avoid `last arg as keyword param` warning when building user middleware on Ruby 2.7 (#1153 @dgholz)
70
+ * Limits net-http-persistent version to < 4.0 (#1156 @iMacTia)
71
+ * Update `typhoeus` to new stable version (`1.4`) (#1159 @AlexWayfer)
72
+ * Properly fix test failure with Rack 2.1+. (#1171 @voxik)
73
+
74
+ ### Documentation
75
+
76
+ * Improves documentation on how to contribute to the site by using Docker. (#1175 @iMacTia)
77
+ * Remove retry_change_requests from documentation (#1185 @stim371)
78
+
79
+ ### Misc
80
+
81
+ * Link from GitHub Actions badge to CI workflow (#1141 @olleolleolle)
82
+ * Return tests of `Test` adapter (#1147 @AlexWayfer)
83
+ * Add 1.0 release to wording in CONTRIBUTING (#1155 @olleolleolle)
84
+ * Fix linting bumping Rubocop to 0.90.0 (#1182 @iMacTia)
85
+ * Drop `git ls-files` in gemspec (#1183 @utkarsh2102)
86
+ * Upgrade CI to ruby/setup-ruby (#1187 @gogainda)
87
+
88
+ ## [v1.0.1](https://github.com/lostisland/faraday/releases/tag/v1.0.1) (2020-03-29)
89
+
90
+ ### Fixes
91
+
92
+ * Use Net::HTTP#start(&block) to ensure closed TCP connections (#1117)
93
+ * Fully qualify constants to be checked (#1122)
94
+ * Allows `parse` method to be private/protected in response middleware (#1123)
95
+ * Encode Spaces in Query Strings as '%20' Instead of '+' (#1125)
96
+ * Limits rack to v2.0.x (#1127)
97
+ * Adapter Registry reads also use mutex (#1136)
98
+
99
+ ### Documentation
100
+
101
+ * Retry middleware documentation fix (#1109)
102
+ * Docs(retry): precise usage of retry-after (#1111)
103
+ * README: Link the logo to the website (#1112)
104
+ * Website: add search bar (#1116)
105
+ * Fix request/response mix-up in docs text (#1132)
106
+
3
107
  ## v1.0
4
108
 
5
109
  Features:
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
4
4
  [![GitHub Actions CI](https://github.com/lostisland/faraday/workflows/CI/badge.svg)](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/f869daab091ceef1da73/maintainability)](https://codeclimate.com/github/lostisland/faraday/maintainability)
6
5
  [![Gitter](https://badges.gitter.im/lostisland/faraday.svg)](https://gitter.im/lostisland/faraday?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
6
 
8
7
 
@@ -47,7 +46,7 @@ But before you start coding, please read our [Contributing Guide][contributing]
47
46
  [website]: https://lostisland.github.io/faraday
48
47
  [faraday_team]: https://lostisland.github.io/faraday/team
49
48
  [contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
50
- [apidoc]: http://www.rubydoc.info/gems/faraday
49
+ [apidoc]: https://www.rubydoc.info/github/lostisland/faraday
51
50
  [actions]: https://github.com/lostisland/faraday/actions
52
51
  [jruby]: http://jruby.org/
53
52
  [rubinius]: http://rubini.us/
@@ -12,8 +12,8 @@ class Client
12
12
  @conn = conn
13
13
  end
14
14
 
15
- def sushi(jname)
16
- res = @conn.get("/#{jname}")
15
+ def sushi(jname, params: {})
16
+ res = @conn.get("/#{jname}", params)
17
17
  data = JSON.parse(res.body)
18
18
  data['name']
19
19
  end
@@ -62,4 +62,36 @@ RSpec.describe Client do
62
62
  expect { client.sushi('ebi') }.to raise_error(Faraday::ConnectionFailed)
63
63
  stubs.verify_stubbed_calls
64
64
  end
65
+
66
+ context 'When the test stub is run in strict_mode' do
67
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new(strict_mode: true) }
68
+
69
+ it 'verifies the all parameter values are identical' do
70
+ stubs.get('/ebi?abc=123') do
71
+ [
72
+ 200,
73
+ { 'Content-Type': 'application/javascript' },
74
+ '{"name": "shrimp"}'
75
+ ]
76
+ end
77
+
78
+ # uncomment to raise Stubs::NotFound
79
+ # expect(client.sushi('ebi', params: { abc: 123, foo: 'Kappa' })).to eq('shrimp')
80
+ expect(client.sushi('ebi', params: { abc: 123 })).to eq('shrimp')
81
+ stubs.verify_stubbed_calls
82
+ end
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
65
97
  end
@@ -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
@@ -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
@@ -25,6 +25,9 @@ module Faraday
25
25
  # "showing item: #{meta[:match_data][1]}"
26
26
  # ]
27
27
  # end
28
+ #
29
+ # # You can set strict_mode to exactly match the stubbed requests.
30
+ # stub.strict_mode = true
28
31
  # end
29
32
  # end
30
33
  #
@@ -47,10 +50,11 @@ module Faraday
47
50
  class NotFound < StandardError
48
51
  end
49
52
 
50
- def initialize
53
+ def initialize(strict_mode: false)
51
54
  # { get: [Stub, Stub] }
52
55
  @stack = {}
53
56
  @consumed = {}
57
+ @strict_mode = strict_mode
54
58
  yield(self) if block_given?
55
59
  end
56
60
 
@@ -58,18 +62,20 @@ module Faraday
58
62
  @stack.empty?
59
63
  end
60
64
 
61
- def match(request_method, host, path, headers, body)
65
+ # @param env [Faraday::Env]
66
+ def match(env)
67
+ request_method = env[:method]
62
68
  return false unless @stack.key?(request_method)
63
69
 
64
70
  stack = @stack[request_method]
65
71
  consumed = (@consumed[request_method] ||= [])
66
72
 
67
- stub, meta = matches?(stack, host, path, headers, body)
73
+ stub, meta = matches?(stack, env)
68
74
  if stub
69
75
  consumed << stack.delete(stub)
70
76
  return stub, meta
71
77
  end
72
- matches?(consumed, host, path, headers, body)
78
+ matches?(consumed, env)
73
79
  end
74
80
 
75
81
  def get(path, headers = {}, &block)
@@ -115,6 +121,17 @@ module Faraday
115
121
  raise failed_stubs.join(' ') unless failed_stubs.empty?
116
122
  end
117
123
 
124
+ # Set strict_mode. If the value is true, this adapter tries to find matched requests strictly,
125
+ # which means that all of a path, parameters, and headers must be the same as an actual request.
126
+ def strict_mode=(value)
127
+ @strict_mode = value
128
+ @stack.each do |_method, stubs|
129
+ stubs.each do |stub|
130
+ stub.strict_mode = value
131
+ end
132
+ end
133
+ end
134
+
118
135
  protected
119
136
 
120
137
  def new_stub(request_method, path, headers = {}, body = nil, &block)
@@ -127,14 +144,18 @@ module Faraday
127
144
  Faraday::Utils.URI(path).host
128
145
  ]
129
146
  end
147
+ path, query = normalized_path.respond_to?(:split) ? normalized_path.split('?') : normalized_path
148
+ headers = Utils::Headers.new(headers)
130
149
 
131
- stub = Stub.new(host, normalized_path, headers, body, block)
150
+ stub = Stub.new(host, path, query, headers, body, @strict_mode, block)
132
151
  (@stack[request_method] ||= []) << stub
133
152
  end
134
153
 
135
- def matches?(stack, host, path, headers, body)
154
+ # @param stack [Hash]
155
+ # @param env [Faraday::Env]
156
+ def matches?(stack, env)
136
157
  stack.each do |stub|
137
- match_result, meta = stub.matches?(host, path, headers, body)
158
+ match_result, meta = stub.matches?(env)
138
159
  return stub, meta if match_result
139
160
  end
140
161
  nil
@@ -142,35 +163,20 @@ module Faraday
142
163
  end
143
164
 
144
165
  # Stub request
145
- # rubocop:disable Style/StructInheritance
146
- class Stub < Struct.new(:host, :path, :params, :headers, :body, :block)
147
- # rubocop:enable Style/StructInheritance
148
- def initialize(host, full, headers, body, block)
149
- path, query = full.respond_to?(:split) ? full.split('?') : full
150
- params =
151
- if query
152
- Faraday::Utils.parse_nested_query(query)
153
- else
154
- {}
155
- end
156
-
157
- super(host, path, params, headers, body, block)
158
- 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]
159
173
 
160
- def matches?(request_host, request_uri, request_headers, request_body)
161
- request_path, request_query = request_uri.split('?')
162
- request_params =
163
- if request_query
164
- Faraday::Utils.parse_nested_query(request_query)
165
- else
166
- {}
167
- end
168
174
  # meta is a hash used as carrier
169
175
  # that will be yielded to consumer block
170
176
  meta = {}
171
177
  [(host.nil? || host == request_host) &&
172
178
  path_match?(request_path, meta) &&
173
- params_match?(request_params) &&
179
+ params_match?(env) &&
174
180
  (body.to_s.size.zero? || request_body == body) &&
175
181
  headers_match?(request_headers), meta]
176
182
  end
@@ -183,13 +189,30 @@ module Faraday
183
189
  end
184
190
  end
185
191
 
186
- def params_match?(request_params)
192
+ # @param env [Faraday::Env]
193
+ def params_match?(env)
194
+ request_params = env[:params]
195
+ params = env.params_encoder.decode(query) || {}
196
+
197
+ if strict_mode
198
+ return Set.new(params) == Set.new(request_params)
199
+ end
200
+
187
201
  params.keys.all? do |key|
188
202
  request_params[key] == params[key]
189
203
  end
190
204
  end
191
205
 
192
206
  def headers_match?(request_headers)
207
+ if strict_mode
208
+ headers_with_user_agent = headers.dup.tap do |hs|
209
+ # NOTE: Set User-Agent in case it's not set when creating Stubs.
210
+ # Users would not want to set Faraday's User-Agent explicitly.
211
+ hs[:user_agent] ||= Connection::USER_AGENT
212
+ end
213
+ return Set.new(headers_with_user_agent) == Set.new(request_headers)
214
+ end
215
+
193
216
  headers.keys.all? do |key|
194
217
  request_headers[key] == headers[key]
195
218
  end
@@ -210,26 +233,19 @@ module Faraday
210
233
  yield(stubs)
211
234
  end
212
235
 
236
+ # @param env [Faraday::Env]
213
237
  def call(env)
214
238
  super
215
- host = env[:url].host
216
- normalized_path = Faraday::Utils.normalize_path(env[:url])
217
- params_encoder = env.request.params_encoder ||
218
- Faraday::Utils.default_params_encoder
219
239
 
220
- stub, meta = stubs.match(env[:method], host, normalized_path,
221
- env.request_headers, env[:body])
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)
222
243
 
223
244
  unless stub
224
245
  raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\
225
- "#{normalized_path} #{env[:body]}"
246
+ "#{env[:url]} #{env[:body]}"
226
247
  end
227
248
 
228
- env[:params] = if (query = env[:url].query)
229
- params_encoder.decode(query)
230
- else
231
- {}
232
- end
233
249
  block_arity = stub.block.arity
234
250
  status, headers, body =
235
251
  if block_arity >= 0
@@ -11,18 +11,7 @@ module Faraday
11
11
 
12
12
  register_middleware File.expand_path('adapter', __dir__),
13
13
  test: [:Test, 'test'],
14
- net_http: [:NetHttp, 'net_http'],
15
- net_http_persistent: [
16
- :NetHttpPersistent,
17
- 'net_http_persistent'
18
- ],
19
- typhoeus: [:Typhoeus, 'typhoeus'],
20
- patron: [:Patron, 'patron'],
21
- em_synchrony: [:EMSynchrony, 'em_synchrony'],
22
- em_http: [:EMHttp, 'em_http'],
23
- excon: [:Excon, 'excon'],
24
- rack: [:Rack, 'rack'],
25
- httpclient: [:HTTPClient, 'httpclient']
14
+ typhoeus: [:Typhoeus, 'typhoeus']
26
15
 
27
16
  # This module marks an Adapter as supporting parallel requests.
28
17
  module Parallelism
@@ -58,16 +58,8 @@ module Faraday
58
58
  class Adapter
59
59
  extend AutoloadHelper
60
60
  autoload_all 'faraday/adapter',
61
- NetHttp: 'net_http',
62
- NetHttpPersistent: 'net_http_persistent',
63
- EMSynchrony: 'em_synchrony',
64
- EMHttp: 'em_http',
65
61
  Typhoeus: 'typhoeus',
66
- Patron: 'patron',
67
- Excon: 'excon',
68
- Test: 'test',
69
- Rack: 'rack',
70
- HTTPClient: 'httpclient'
62
+ Test: 'test'
71
63
  end
72
64
 
73
65
  # Request represents a single HTTP request for a Faraday adapter to make.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'faraday/deprecate'
4
+
3
5
  module Faraday
4
6
  # Connection objects manage the default properties and the middleware
5
7
  # stack for fulfilling an HTTP request.
@@ -15,6 +17,7 @@ module Faraday
15
17
  class Connection
16
18
  # A Set of allowed HTTP verbs.
17
19
  METHODS = Set.new %i[get post put delete head patch options trace]
20
+ USER_AGENT = "Faraday v#{VERSION}"
18
21
 
19
22
  # @return [Hash] URI query unencoded key/value pairs.
20
23
  attr_reader :params
@@ -26,7 +29,7 @@ module Faraday
26
29
  # Connection. This includes a default host name, scheme, port, and path.
27
30
  attr_reader :url_prefix
28
31
 
29
- # @return [Faraday::Builder] Builder for this Connection.
32
+ # @return [Faraday::RackBuilder] Builder for this Connection.
30
33
  attr_reader :builder
31
34
 
32
35
  # @return [Hash] SSL options.
@@ -73,6 +76,7 @@ module Faraday
73
76
  @options = options.request
74
77
  @ssl = options.ssl
75
78
  @default_parallel_manager = options.parallel_manager
79
+ @manual_proxy = nil
76
80
 
77
81
  @builder = options.builder || begin
78
82
  # pass an empty block to Builder so it doesn't assume default middleware
@@ -88,7 +92,7 @@ module Faraday
88
92
 
89
93
  yield(self) if block_given?
90
94
 
91
- @headers[:user_agent] ||= "Faraday v#{VERSION}"
95
+ @headers[:user_agent] ||= USER_AGENT
92
96
  end
93
97
 
94
98
  def initialize_proxy(url, options)
@@ -298,6 +302,9 @@ module Faraday
298
302
  set_authorization_header(:basic_auth, login, pass)
299
303
  end
300
304
 
305
+ extend Faraday::Deprecate
306
+ deprecate :basic_auth, '#request(:basic_auth, ...)', '2.0'
307
+
301
308
  # Sets up the Authorization header with the given token.
302
309
  #
303
310
  # @param token [String]
@@ -315,6 +322,11 @@ module Faraday
315
322
  set_authorization_header(:token_auth, token, options)
316
323
  end
317
324
 
325
+ deprecate :token_auth,
326
+ '#request(:token_auth, ...)',
327
+ '2.0',
328
+ 'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'
329
+
318
330
  # Sets up a custom Authorization header.
319
331
  #
320
332
  # @param type [String] authorization type
@@ -337,6 +349,11 @@ module Faraday
337
349
  set_authorization_header(:authorization, type, token)
338
350
  end
339
351
 
352
+ deprecate :authorization,
353
+ '#request(:authorization, ...)',
354
+ '2.0',
355
+ 'See https://lostisland.github.io/faraday/middleware/authentication for more usage info.'
356
+
340
357
  # Check if the adapter is parallel-capable.
341
358
  #
342
359
  # @yield if the adapter isn't parallel-capable, or if no adapter is set yet.
@@ -416,9 +433,16 @@ module Faraday
416
433
  uri.query = nil
417
434
 
418
435
  with_uri_credentials(uri) do |user, password|
419
- basic_auth user, password
436
+ set_basic_auth(user, password)
420
437
  uri.user = uri.password = nil
421
438
  end
439
+
440
+ @proxy = proxy_from_env(url) unless @manual_proxy
441
+ end
442
+
443
+ def set_basic_auth(user, password)
444
+ header = Faraday::Request::BasicAuthentication.header(user, password)
445
+ headers[Faraday::Request::Authorization::KEY] = header
422
446
  end
423
447
 
424
448
  # Sets the path prefix and ensures that it always has a leading
@@ -517,11 +541,11 @@ module Faraday
517
541
  # @return [URI]
518
542
  def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
519
543
  url = nil if url.respond_to?(:empty?) && url.empty?
520
- base = url_prefix
544
+ base = url_prefix.dup
521
545
  if url && base.path && base.path !~ %r{/$}
522
- base = base.dup
523
546
  base.path = "#{base.path}/" # ensure trailing slash
524
547
  end
548
+ url = url && URI.parse(url.to_s).opaque ? url.to_s.gsub(':', '%3A') : url
525
549
  uri = url ? base + url : base
526
550
  if params
527
551
  uri.query = params.to_query(params_encoder || options.params_encoder)
@@ -576,7 +600,11 @@ module Faraday
576
600
  case url
577
601
  when String
578
602
  uri = Utils.URI(url)
579
- uri = URI.parse("#{uri.scheme}://#{uri.hostname}").find_proxy
603
+ uri = if uri.host.nil?
604
+ find_default_proxy
605
+ else
606
+ URI.parse("#{uri.scheme}://#{uri.host}").find_proxy
607
+ end
580
608
  when URI
581
609
  uri = url.find_proxy
582
610
  when nil