faraday 2.10.1 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d6b48adceee9f714528016d437777166311c5108695c0e1bfa7ae98bfe494bd
4
- data.tar.gz: c678d859ccbfe156f6aac0ba6b83619c2243705b7c2339a007c45c0f7559b3af
3
+ metadata.gz: 22c3a83dd32f012eb6d4bf4fe79b3e95ce44979ac19aee42a533d88f5c27848e
4
+ data.tar.gz: c07d8eda18dcde723ee2ab365a5d46272c88dab63cbadecd7f3d4af6e6133f9e
5
5
  SHA512:
6
- metadata.gz: 41bd0de3c358c55c1c64c1b54ab22b2cec9830fa12188d1c6886493373c7fe2c8ff1ffcccabdc0b4e15145f627dd5bcb184ec4a612428cb2cc2b0b57190b5c15
7
- data.tar.gz: cfa8ce000d7e40a809b0300a8e3e6af5d191aab4836bc3613ce042446f3c0ea6c87313fe6f7ac8a6381d167913e5fb9e84899a084514fb9873bceebbf6846610
6
+ metadata.gz: 728dafd34ea29e515627f14bb254c83729ca66470961505d332994bf9ee52de85d43b97969fd0ce5cb9db22fbdf43b8ac0d64ee9447c336f5fcc6be6adc0d737
7
+ data.tar.gz: 1f28a98be9151d77ec729cabc40faa0c11cc27283382925452e6076e20cc5321b63732492d9dc10fb65a35977b18b957e636e72e22686c2467d91de9a038fae8
data/CHANGELOG.md CHANGED
@@ -517,7 +517,7 @@ Breaking changes:
517
517
  - Drop support for Ruby 1.8
518
518
 
519
519
  Features:
520
- - Include wrapped exception/reponse in ClientErrors
520
+ - Include wrapped exception/response in ClientErrors
521
521
  - Add `response.reason_phrase`
522
522
  - Provide option to selectively skip logging request/response headers
523
523
  - Add regex support for pattern matching in `test` adapter
@@ -314,15 +314,23 @@ module Faraday
314
314
  #
315
315
  # @yield a block to execute multiple requests.
316
316
  # @return [void]
317
- def in_parallel(manager = nil)
317
+ def in_parallel(manager = nil, &block)
318
318
  @parallel_manager = manager || default_parallel_manager do
319
319
  warn 'Warning: `in_parallel` called but no parallel-capable adapter ' \
320
320
  'on Faraday stack'
321
321
  warn caller[2, 10].join("\n")
322
322
  nil
323
323
  end
324
- yield
325
- @parallel_manager&.run
324
+ return yield unless @parallel_manager
325
+
326
+ if @parallel_manager.respond_to?(:execute)
327
+ # Execute is the new method that is responsible for executing the block.
328
+ @parallel_manager.execute(&block)
329
+ else
330
+ # TODO: Old behaviour, deprecate and remove in 3.0
331
+ yield
332
+ @parallel_manager.run
333
+ end
326
334
  ensure
327
335
  @parallel_manager = nil
328
336
  end
@@ -46,12 +46,15 @@ module Faraday
46
46
  # #
47
47
  # # @!attribute max_version
48
48
  # # @return [String, Symbol] maximum SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-max_version-3D)
49
+ # #
50
+ # # @!attribute ciphers
51
+ # # @return [String] cipher list in OpenSSL format (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-ciphers-3D)
49
52
  # class SSLOptions < Options; end
50
53
  SSLOptions = Options.new(:verify, :verify_hostname,
51
54
  :ca_file, :ca_path, :verify_mode,
52
55
  :cert_store, :client_cert, :client_key,
53
56
  :certificate, :private_key, :verify_depth,
54
- :version, :min_version, :max_version) do
57
+ :version, :min_version, :max_version, :ciphers) do
55
58
  # @return [Boolean] true if should verify
56
59
  def verify?
57
60
  verify != false
@@ -8,32 +8,30 @@ module Faraday
8
8
  # rubocop:disable Naming/ConstantName
9
9
  ClientErrorStatuses = (400...500)
10
10
  ServerErrorStatuses = (500...600)
11
+ ClientErrorStatusesWithCustomExceptions = {
12
+ 400 => Faraday::BadRequestError,
13
+ 401 => Faraday::UnauthorizedError,
14
+ 403 => Faraday::ForbiddenError,
15
+ 404 => Faraday::ResourceNotFound,
16
+ 408 => Faraday::RequestTimeoutError,
17
+ 409 => Faraday::ConflictError,
18
+ 422 => Faraday::UnprocessableEntityError,
19
+ 429 => Faraday::TooManyRequestsError
20
+ }.freeze
11
21
  # rubocop:enable Naming/ConstantName
12
22
 
13
- DEFAULT_OPTIONS = { include_request: true }.freeze
23
+ DEFAULT_OPTIONS = { include_request: true, allowed_statuses: [] }.freeze
14
24
 
15
25
  def on_complete(env)
26
+ return if Array(options[:allowed_statuses]).include?(env[:status])
27
+
16
28
  case env[:status]
17
- when 400
18
- raise Faraday::BadRequestError, response_values(env)
19
- when 401
20
- raise Faraday::UnauthorizedError, response_values(env)
21
- when 403
22
- raise Faraday::ForbiddenError, response_values(env)
23
- when 404
24
- raise Faraday::ResourceNotFound, response_values(env)
29
+ when *ClientErrorStatusesWithCustomExceptions.keys
30
+ raise ClientErrorStatusesWithCustomExceptions[env[:status]], response_values(env)
25
31
  when 407
26
32
  # mimic the behavior that we get with proxy requests with HTTPS
27
33
  msg = %(407 "Proxy Authentication Required")
28
34
  raise Faraday::ProxyAuthError.new(msg, response_values(env))
29
- when 408
30
- raise Faraday::RequestTimeoutError, response_values(env)
31
- when 409
32
- raise Faraday::ConflictError, response_values(env)
33
- when 422
34
- raise Faraday::UnprocessableEntityError, response_values(env)
35
- when 429
36
- raise Faraday::TooManyRequestsError, response_values(env)
37
35
  when ClientErrorStatuses
38
36
  raise Faraday::ClientError, response_values(env)
39
37
  when ServerErrorStatuses
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.10.1'
4
+ VERSION = '2.12.0'
5
5
  end
@@ -252,4 +252,24 @@ RSpec.describe Faraday::Response::RaiseError do
252
252
  end
253
253
  end
254
254
  end
255
+
256
+ describe 'allowing certain status codes' do
257
+ let(:conn) do
258
+ Faraday.new do |b|
259
+ b.response :raise_error, allowed_statuses: [404]
260
+ b.adapter :test do |stub|
261
+ stub.get('bad-request') { [400, { 'X-Reason' => 'because' }, 'keep looking'] }
262
+ stub.get('not-found') { [404, { 'X-Reason' => 'because' }, 'keep looking'] }
263
+ end
264
+ end
265
+ end
266
+
267
+ it 'raises an error for status codes that are not explicitly allowed' do
268
+ expect { conn.get('bad-request') }.to raise_error(Faraday::BadRequestError)
269
+ end
270
+
271
+ it 'does not raise an error for allowed status codes' do
272
+ expect { conn.get('not-found') }.not_to raise_error
273
+ end
274
+ end
255
275
  end
@@ -103,7 +103,8 @@ RSpec.describe Faraday::Utils do
103
103
  version: '2',
104
104
  min_version: nil,
105
105
  max_version: nil,
106
- verify_hostname: nil
106
+ verify_hostname: nil,
107
+ ciphers: nil
107
108
  }
108
109
  end
109
110
 
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.10.1
4
+ version: 2.12.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: 2024-07-31 00:00:00.000000000 Z
13
+ date: 2024-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday-net_http
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.0'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '3.2'
24
+ version: '3.4'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,21 @@ dependencies:
31
31
  version: '2.0'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '3.2'
34
+ version: '3.4'
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: logger
37
51
  requirement: !ruby/object:Gem::Requirement
@@ -132,9 +146,10 @@ licenses:
132
146
  - MIT
133
147
  metadata:
134
148
  homepage_uri: https://lostisland.github.io/faraday
135
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.10.1
149
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.12.0
136
150
  source_code_uri: https://github.com/lostisland/faraday
137
151
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
152
+ rubygems_mfa_required: 'true'
138
153
  post_install_message:
139
154
  rdoc_options: []
140
155
  require_paths:
@@ -151,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
166
  - !ruby/object:Gem::Version
152
167
  version: '0'
153
168
  requirements: []
154
- rubygems_version: 3.5.11
169
+ rubygems_version: 3.5.16
155
170
  signing_key:
156
171
  specification_version: 4
157
172
  summary: HTTP/REST API client library.