faraday 2.7.1 → 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: 655acb55a8ad9a7088984d61b2e520fdf11e5aa3d9221212ef6e783349d72614
4
- data.tar.gz: 620ec5a7c8c76109f6b82462b7a40b6440d79a96f6beaff33164be8743f1db7d
3
+ metadata.gz: f899a961a641f50ece2674f527bd58e72a538421a404cdef33fd89457907f9da
4
+ data.tar.gz: 305172dd0e2dad3c58b8c41efde3524064efdea1071d8e254c5f08bf99738666
5
5
  SHA512:
6
- metadata.gz: bc0321f9fed0b30548454555345bc4fa26af757142fd4dd767868c281bdc50b5833b73aa005c48dbc638c3c2f0dff00dddcde6d313a2e2cf25eae15dca928d3a
7
- data.tar.gz: 3ebe07829ccb50bb0a0d1d0a5e77d2d91fb8ff6c57dd7d107792f8a6ef92656c4c8e67e650f2ac88862686f1051d36cabc1b9fd5ec933b59e70977d0777a5845
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.
@@ -37,16 +37,16 @@ module Faraday
37
37
  log_body('response', env[:body]) if env[:body] && log_body?(:response)
38
38
  end
39
39
 
40
- def error(error)
40
+ def exception(exc)
41
41
  return unless log_errors?
42
42
 
43
- error_log = proc { error.full_message }
43
+ error_log = proc { exc.full_message }
44
44
  public_send(log_level, 'error', &error_log)
45
45
 
46
- log_headers('error', error.response_headers) if error.respond_to?(:response_headers) && log_headers?(:error)
47
- 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)
48
48
 
49
- log_body('error', error.response_body)
49
+ log_body('error', exc.response_body)
50
50
  end
51
51
 
52
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.1'
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.1
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-18 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.1
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: