faraday 2.7.0 → 2.7.2

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: aded1d146b09e5b537b81833177fcd70acbed297598160e1114807fe047c15c2
4
- data.tar.gz: 3b4c82d7712d3667767da96b87050d0cdb76bc0d0d2ed3f67d7f7ccb595f474e
3
+ metadata.gz: f899a961a641f50ece2674f527bd58e72a538421a404cdef33fd89457907f9da
4
+ data.tar.gz: 305172dd0e2dad3c58b8c41efde3524064efdea1071d8e254c5f08bf99738666
5
5
  SHA512:
6
- metadata.gz: 6e37eda4374f7c99ea8e687a6c704fcc74935800c4209c5b94767737e2133dc343dcfaa49deda11ddd312fe6f8e8b661a765134b402d3aa787672ffc84026547
7
- data.tar.gz: 8ce5708af5954af94fdb2c1aff6a4cefcf7ed512d2f91d05c7ac3cdfc72fcad2840e9674c5defb8aaed570e5c9e5f2324911fb22e4b05184b2597a87959f2853
6
+ metadata.gz: 43fcdfdcf33960a86e7b8fbabe911cce6de6f862de2513541eb4579e71ca5eb9bf1255652c8ea88d4e93eb881346e22a46a1dac0baeedf081d18fcd583d8d7b8
7
+ data.tar.gz: 997c91527eec820c93a614943dcc86a611fc4cfbda3c9e29204cf344caf62004f929e8ae71717a453925d02671b148c7c52c13977603bb9e7831adfc7bf24fba
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'timeout'
4
+
3
5
  module Faraday
4
6
  class Adapter
5
7
  # @example
@@ -277,11 +279,22 @@ module Faraday
277
279
  end
278
280
 
279
281
  block_arity = stub.block.arity
282
+ params = if block_arity >= 0
283
+ [env, meta].take(block_arity)
284
+ else
285
+ [env, meta]
286
+ end
287
+
288
+ timeout = request_timeout(:open, env[:request])
289
+ timeout ||= request_timeout(:read, env[:request])
290
+
280
291
  status, headers, body =
281
- if block_arity >= 0
282
- stub.block.call(*[env, meta].take(block_arity))
292
+ if timeout
293
+ ::Timeout.timeout(timeout, Faraday::TimeoutError) do
294
+ stub.block.call(*params)
295
+ end
283
296
  else
284
- stub.block.call(env, meta)
297
+ stub.block.call(*params)
285
298
  end
286
299
 
287
300
  # We need to explicitly pass `reason_phrase = nil` here to avoid keyword args conflicts.
@@ -78,8 +78,7 @@ module Faraday
78
78
  # @param type [Symbol] Describes which timeout setting to get: :read,
79
79
  # :write, or :open.
80
80
  # @param options [Hash] Hash containing Symbol keys like :timeout,
81
- # :read_timeout, :write_timeout, :open_timeout, or
82
- # :timeout
81
+ # :read_timeout, :write_timeout, or :open_timeout
83
82
  #
84
83
  # @return [Integer, nil] Timeout duration in seconds, or nil if no timeout
85
84
  # has been set.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pp' # rubocop:disable Lint/RedundantRequireStatement
4
+
3
5
  module Faraday
4
6
  module Logging
5
7
  # Serves as an integration point to customize logging
@@ -35,16 +37,16 @@ module Faraday
35
37
  log_body('response', env[:body]) if env[:body] && log_body?(:response)
36
38
  end
37
39
 
38
- def error(error)
40
+ def exception(exc)
39
41
  return unless log_errors?
40
42
 
41
- error_log = proc { error.full_message }
43
+ error_log = proc { exc.full_message }
42
44
  public_send(log_level, 'error', &error_log)
43
45
 
44
- log_headers('error', error.response_headers) if error.respond_to?(:response_headers) && log_headers?(:error)
45
- return unless error.respond_to?(:response_body) && error.response_body && log_body?(:error)
46
+ log_headers('error', exc.response_headers) if exc.respond_to?(:response_headers) && log_headers?(:error)
47
+ return unless exc.respond_to?(:response_body) && exc.response_body && log_body?(:error)
46
48
 
47
- log_body('error', error.response_body)
49
+ log_body('error', exc.response_body)
48
50
  end
49
51
 
50
52
  def filter(filter_word, filter_replacement)
@@ -27,8 +27,8 @@ module Faraday
27
27
  @formatter.response(env)
28
28
  end
29
29
 
30
- def on_error(error)
31
- @formatter.error(error) if @formatter.respond_to?(:error)
30
+ def on_error(exc)
31
+ @formatter.exception(exc) if @formatter.respond_to?(:exception)
32
32
  end
33
33
  end
34
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.7.0'
4
+ VERSION = '2.7.2'
5
5
  end
@@ -410,4 +410,33 @@ RSpec.describe Faraday::Adapter::Test do
410
410
  end
411
411
  end
412
412
  end
413
+
414
+ describe 'request timeout' do
415
+ subject(:request) do
416
+ connection.get('/sleep') do |req|
417
+ req.options.timeout = timeout
418
+ end
419
+ end
420
+
421
+ before do
422
+ stubs.get('/sleep') do
423
+ sleep(0.01)
424
+ [200, {}, '']
425
+ end
426
+ end
427
+
428
+ context 'when request is within timeout' do
429
+ let(:timeout) { 1 }
430
+
431
+ it { expect(request.status).to eq 200 }
432
+ end
433
+
434
+ context 'when request is too slow' do
435
+ let(:timeout) { 0.001 }
436
+
437
+ it 'raises an exception' do
438
+ expect { request }.to raise_error(Faraday::TimeoutError)
439
+ end
440
+ end
441
+ end
413
442
  end
@@ -68,7 +68,7 @@ RSpec.describe Faraday::Response::Logger do
68
68
  context 'when no route' do
69
69
  it 'delegates logging to the formatter' do
70
70
  expect(formatter).to receive(:request).with(an_instance_of(Faraday::Env))
71
- expect(formatter).to receive(:error).with(an_instance_of(Faraday::Adapter::Test::Stubs::NotFound))
71
+ expect(formatter).to receive(:exception).with(an_instance_of(Faraday::Adapter::Test::Stubs::NotFound))
72
72
 
73
73
  expect { conn.get '/noroute' }.to raise_error(Faraday::Adapter::Test::Stubs::NotFound)
74
74
  end
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.7.0
4
+ version: 2.7.2
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-11-15 00:00:00.000000000 Z
13
+ date: 2022-12-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday-net_http
@@ -131,7 +131,7 @@ licenses:
131
131
  - MIT
132
132
  metadata:
133
133
  homepage_uri: https://lostisland.github.io/faraday
134
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.0
134
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.2
135
135
  source_code_uri: https://github.com/lostisland/faraday
136
136
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
137
137
  post_install_message: