faraday 2.7.0 → 2.7.2
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/lib/faraday/adapter/test.rb +16 -3
- data/lib/faraday/adapter.rb +1 -2
- data/lib/faraday/logging/formatter.rb +7 -5
- data/lib/faraday/response/logger.rb +2 -2
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/adapter/test_spec.rb +29 -0
- data/spec/faraday/response/logger_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f899a961a641f50ece2674f527bd58e72a538421a404cdef33fd89457907f9da
|
4
|
+
data.tar.gz: 305172dd0e2dad3c58b8c41efde3524064efdea1071d8e254c5f08bf99738666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43fcdfdcf33960a86e7b8fbabe911cce6de6f862de2513541eb4579e71ca5eb9bf1255652c8ea88d4e93eb881346e22a46a1dac0baeedf081d18fcd583d8d7b8
|
7
|
+
data.tar.gz: 997c91527eec820c93a614943dcc86a611fc4cfbda3c9e29204cf344caf62004f929e8ae71717a453925d02671b148c7c52c13977603bb9e7831adfc7bf24fba
|
data/lib/faraday/adapter/test.rb
CHANGED
@@ -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
|
282
|
-
|
292
|
+
if timeout
|
293
|
+
::Timeout.timeout(timeout, Faraday::TimeoutError) do
|
294
|
+
stub.block.call(*params)
|
295
|
+
end
|
283
296
|
else
|
284
|
-
stub.block.call(
|
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.
|
data/lib/faraday/adapter.rb
CHANGED
@@ -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
|
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
|
40
|
+
def exception(exc)
|
39
41
|
return unless log_errors?
|
40
42
|
|
41
|
-
error_log = proc {
|
43
|
+
error_log = proc { exc.full_message }
|
42
44
|
public_send(log_level, 'error', &error_log)
|
43
45
|
|
44
|
-
log_headers('error',
|
45
|
-
return unless
|
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',
|
49
|
+
log_body('error', exc.response_body)
|
48
50
|
end
|
49
51
|
|
50
52
|
def filter(filter_word, filter_replacement)
|
data/lib/faraday/version.rb
CHANGED
@@ -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(:
|
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.
|
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-
|
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.
|
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:
|