faraday 2.10.0 → 2.13.1
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/CHANGELOG.md +1 -1
- data/lib/faraday/connection.rb +11 -3
- data/lib/faraday/logging/formatter.rb +6 -6
- data/lib/faraday/middleware.rb +2 -5
- data/lib/faraday/options/env.rb +1 -1
- data/lib/faraday/options/proxy_options.rb +4 -2
- data/lib/faraday/options/ssl_options.rb +8 -2
- data/lib/faraday/rack_builder.rb +20 -19
- data/lib/faraday/response/logger.rb +5 -3
- data/lib/faraday/response/raise_error.rb +15 -17
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/error_spec.rb +10 -2
- data/spec/faraday/options/proxy_options_spec.rb +27 -0
- data/spec/faraday/response/logger_spec.rb +39 -4
- data/spec/faraday/response/raise_error_spec.rb +20 -0
- data/spec/faraday/utils_spec.rb +3 -1
- metadata +21 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ab8d55c7b360596e25721ecc32dcf99c65cea19d04598bb468fc2a422e26146
|
4
|
+
data.tar.gz: 624ddc291aec0a438fded658897b2127d62b8fe10e00590e3ad0a609307711d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2394c6ccb0b3e12d16e2dcd739d8ecf053199b40ce5d8d4a1902cc141c12746190e21b928e4979405ffcb2660db80a4777d46ee839df10f75cb66b34039285e
|
7
|
+
data.tar.gz: d91f5258bb49c40ff720aaba295ab4c86ea975cb7e0d4ad96647921e34924013501c1b4dddcf1c5497488fda0480ef39296f76b16188201f0162da004a490ba5
|
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/
|
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
|
data/lib/faraday/connection.rb
CHANGED
@@ -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
|
-
|
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
|
@@ -23,8 +23,8 @@ module Faraday
|
|
23
23
|
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
24
24
|
|
25
25
|
def request(env)
|
26
|
-
public_send(log_level
|
27
|
-
"#{env.method.upcase} #{apply_filters(env.url.to_s)}"
|
26
|
+
public_send(log_level) do
|
27
|
+
"request: #{env.method.upcase} #{apply_filters(env.url.to_s)}"
|
28
28
|
end
|
29
29
|
|
30
30
|
log_headers('request', env.request_headers) if log_headers?(:request)
|
@@ -32,7 +32,7 @@ module Faraday
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def response(env)
|
35
|
-
public_send(log_level
|
35
|
+
public_send(log_level) { "response: Status #{env.status}" }
|
36
36
|
|
37
37
|
log_headers('response', env.response_headers) if log_headers?(:response)
|
38
38
|
log_body('response', env[:body]) if env[:body] && log_body?(:response)
|
@@ -41,7 +41,7 @@ module Faraday
|
|
41
41
|
def exception(exc)
|
42
42
|
return unless log_errors?
|
43
43
|
|
44
|
-
public_send(log_level
|
44
|
+
public_send(log_level) { "error: #{exc.full_message}" }
|
45
45
|
|
46
46
|
log_headers('error', exc.response_headers) if exc.respond_to?(:response_headers) && log_headers?(:error)
|
47
47
|
return unless exc.respond_to?(:response_body) && exc.response_body && log_body?(:error)
|
@@ -107,11 +107,11 @@ module Faraday
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def log_headers(type, headers)
|
110
|
-
public_send(log_level
|
110
|
+
public_send(log_level) { "#{type}: #{apply_filters(dump_headers(headers))}" }
|
111
111
|
end
|
112
112
|
|
113
113
|
def log_body(type, body)
|
114
|
-
public_send(log_level
|
114
|
+
public_send(log_level) { "#{type}: #{apply_filters(dump_body(body))}" }
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
data/lib/faraday/middleware.rb
CHANGED
@@ -10,6 +10,7 @@ module Faraday
|
|
10
10
|
attr_reader :app, :options
|
11
11
|
|
12
12
|
DEFAULT_OPTIONS = {}.freeze
|
13
|
+
LOCK = Mutex.new
|
13
14
|
|
14
15
|
def initialize(app = nil, options = {})
|
15
16
|
@app = app
|
@@ -27,7 +28,7 @@ module Faraday
|
|
27
28
|
#
|
28
29
|
def default_options=(options = {})
|
29
30
|
validate_default_options(options)
|
30
|
-
|
31
|
+
LOCK.synchronize do
|
31
32
|
@default_options = default_options.merge(options)
|
32
33
|
end
|
33
34
|
end
|
@@ -41,10 +42,6 @@ module Faraday
|
|
41
42
|
|
42
43
|
private
|
43
44
|
|
44
|
-
def lock
|
45
|
-
@lock ||= Monitor.new
|
46
|
-
end
|
47
|
-
|
48
45
|
def validate_default_options(options)
|
49
46
|
invalid_keys = options.keys.reject { |opt| self::DEFAULT_OPTIONS.key?(opt) }
|
50
47
|
return unless invalid_keys.any?
|
data/lib/faraday/options/env.rb
CHANGED
@@ -60,7 +60,7 @@ module Faraday
|
|
60
60
|
:reason_phrase, :response_body) do
|
61
61
|
const_set(:ContentLength, 'Content-Length')
|
62
62
|
const_set(:StatusesWithoutBody, Set.new([204, 304]))
|
63
|
-
const_set(:SuccessfulStatuses,
|
63
|
+
const_set(:SuccessfulStatuses, 200..299)
|
64
64
|
|
65
65
|
# A Set of HTTP verbs that typically send a body. If no body is set for
|
66
66
|
# these requests, the Content-Length header is set to 0.
|
@@ -22,8 +22,10 @@ module Faraday
|
|
22
22
|
when URI
|
23
23
|
value = { uri: value }
|
24
24
|
when Hash, Options
|
25
|
-
if
|
26
|
-
value
|
25
|
+
if value[:uri]
|
26
|
+
value = value.dup.tap do |duped|
|
27
|
+
duped[:uri] = Utils.URI(duped[:uri])
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -11,6 +11,9 @@ module Faraday
|
|
11
11
|
# # @return [Boolean] whether to enable hostname verification on server certificates
|
12
12
|
# # during the handshake or not (see https://github.com/ruby/openssl/pull/60)
|
13
13
|
# #
|
14
|
+
# # @!attribute hostname
|
15
|
+
# # @return [String] Server hostname used for SNI (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLSocket.html#method-i-hostname-3D)
|
16
|
+
# #
|
14
17
|
# # @!attribute ca_file
|
15
18
|
# # @return [String] CA file
|
16
19
|
# #
|
@@ -46,12 +49,15 @@ module Faraday
|
|
46
49
|
# #
|
47
50
|
# # @!attribute max_version
|
48
51
|
# # @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)
|
52
|
+
# #
|
53
|
+
# # @!attribute ciphers
|
54
|
+
# # @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
55
|
# class SSLOptions < Options; end
|
50
|
-
SSLOptions = Options.new(:verify, :verify_hostname,
|
56
|
+
SSLOptions = Options.new(:verify, :verify_hostname, :hostname,
|
51
57
|
:ca_file, :ca_path, :verify_mode,
|
52
58
|
:cert_store, :client_cert, :client_key,
|
53
59
|
:certificate, :private_key, :verify_depth,
|
54
|
-
:version, :min_version, :max_version) do
|
60
|
+
:version, :min_version, :max_version, :ciphers) do
|
55
61
|
# @return [Boolean] true if should verify
|
56
62
|
def verify?
|
57
63
|
verify != false
|
data/lib/faraday/rack_builder.rb
CHANGED
@@ -27,10 +27,11 @@ module Faraday
|
|
27
27
|
|
28
28
|
attr_reader :name
|
29
29
|
|
30
|
-
|
30
|
+
def initialize(klass, *args, **kwargs, &block)
|
31
31
|
@name = klass.to_s
|
32
32
|
REGISTRY.set(klass) if klass.respond_to?(:name)
|
33
33
|
@args = args
|
34
|
+
@kwargs = kwargs
|
34
35
|
@block = block
|
35
36
|
end
|
36
37
|
|
@@ -53,7 +54,7 @@ module Faraday
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def build(app = nil)
|
56
|
-
klass.new(app, *@args, &@block)
|
57
|
+
klass.new(app, *@args, **@kwargs, &@block)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -88,52 +89,52 @@ module Faraday
|
|
88
89
|
@handlers.frozen?
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
+
def use(klass, ...)
|
92
93
|
if klass.is_a? Symbol
|
93
|
-
use_symbol(Faraday::Middleware, klass,
|
94
|
+
use_symbol(Faraday::Middleware, klass, ...)
|
94
95
|
else
|
95
96
|
raise_if_locked
|
96
97
|
raise_if_adapter(klass)
|
97
|
-
@handlers << self.class::Handler.new(klass,
|
98
|
+
@handlers << self.class::Handler.new(klass, ...)
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
101
|
-
|
102
|
-
use_symbol(Faraday::Request, key,
|
102
|
+
def request(key, ...)
|
103
|
+
use_symbol(Faraday::Request, key, ...)
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
-
use_symbol(Faraday::Response,
|
106
|
+
def response(...)
|
107
|
+
use_symbol(Faraday::Response, ...)
|
107
108
|
end
|
108
109
|
|
109
|
-
|
110
|
+
def adapter(klass = NO_ARGUMENT, *args, **kwargs, &block)
|
110
111
|
return @adapter if klass == NO_ARGUMENT || klass.nil?
|
111
112
|
|
112
113
|
klass = Faraday::Adapter.lookup_middleware(klass) if klass.is_a?(Symbol)
|
113
|
-
@adapter = self.class::Handler.new(klass, *args, &block)
|
114
|
+
@adapter = self.class::Handler.new(klass, *args, **kwargs, &block)
|
114
115
|
end
|
115
116
|
|
116
117
|
## methods to push onto the various positions in the stack:
|
117
118
|
|
118
|
-
|
119
|
+
def insert(index, ...)
|
119
120
|
raise_if_locked
|
120
121
|
index = assert_index(index)
|
121
|
-
handler = self.class::Handler.new(
|
122
|
+
handler = self.class::Handler.new(...)
|
122
123
|
@handlers.insert(index, handler)
|
123
124
|
end
|
124
125
|
|
125
126
|
alias insert_before insert
|
126
127
|
|
127
|
-
|
128
|
+
def insert_after(index, ...)
|
128
129
|
index = assert_index(index)
|
129
|
-
insert(index + 1,
|
130
|
+
insert(index + 1, ...)
|
130
131
|
end
|
131
132
|
|
132
|
-
|
133
|
+
def swap(index, ...)
|
133
134
|
raise_if_locked
|
134
135
|
index = assert_index(index)
|
135
136
|
@handlers.delete_at(index)
|
136
|
-
insert(index,
|
137
|
+
insert(index, ...)
|
137
138
|
end
|
138
139
|
|
139
140
|
def delete(handler)
|
@@ -237,8 +238,8 @@ module Faraday
|
|
237
238
|
klass <= Faraday::Adapter
|
238
239
|
end
|
239
240
|
|
240
|
-
|
241
|
-
use(mod.lookup_middleware(key),
|
241
|
+
def use_symbol(mod, key, ...)
|
242
|
+
use(mod.lookup_middleware(key), ...)
|
242
243
|
end
|
243
244
|
|
244
245
|
def assert_index(index)
|
@@ -10,11 +10,13 @@ module Faraday
|
|
10
10
|
# lifecycle to a given Logger object. By default, this logs to STDOUT. See
|
11
11
|
# Faraday::Logging::Formatter to see specifically what is logged.
|
12
12
|
class Logger < Middleware
|
13
|
+
DEFAULT_OPTIONS = { formatter: Logging::Formatter }.merge(Logging::Formatter::DEFAULT_OPTIONS).freeze
|
14
|
+
|
13
15
|
def initialize(app, logger = nil, options = {})
|
14
|
-
super(app)
|
16
|
+
super(app, options)
|
15
17
|
logger ||= ::Logger.new($stdout)
|
16
|
-
formatter_class = options.delete(:formatter)
|
17
|
-
@formatter = formatter_class.new(logger: logger, options: options)
|
18
|
+
formatter_class = @options.delete(:formatter)
|
19
|
+
@formatter = formatter_class.new(logger: logger, options: @options)
|
18
20
|
yield @formatter if block_given?
|
19
21
|
end
|
20
22
|
|
@@ -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
|
18
|
-
raise
|
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
|
data/lib/faraday/version.rb
CHANGED
data/spec/faraday/error_spec.rb
CHANGED
@@ -24,7 +24,11 @@ RSpec.describe Faraday::Error do
|
|
24
24
|
it { expect(subject.wrapped_exception).to be_nil }
|
25
25
|
it { expect(subject.response).to eq(exception) }
|
26
26
|
it { expect(subject.message).to eq('the server responded with status 400') }
|
27
|
-
|
27
|
+
if RUBY_VERSION >= '3.4'
|
28
|
+
it { expect(subject.inspect).to eq('#<Faraday::Error response={status: 400}>') }
|
29
|
+
else
|
30
|
+
it { expect(subject.inspect).to eq('#<Faraday::Error response={:status=>400}>') }
|
31
|
+
end
|
28
32
|
it { expect(subject.response_status).to eq(400) }
|
29
33
|
it { expect(subject.response_headers).to be_nil }
|
30
34
|
it { expect(subject.response_body).to be_nil }
|
@@ -61,7 +65,11 @@ RSpec.describe Faraday::Error do
|
|
61
65
|
it { expect(subject.wrapped_exception).to be_nil }
|
62
66
|
it { expect(subject.response).to eq(response) }
|
63
67
|
it { expect(subject.message).to eq('custom message') }
|
64
|
-
|
68
|
+
if RUBY_VERSION >= '3.4'
|
69
|
+
it { expect(subject.inspect).to eq('#<Faraday::Error response={status: 400}>') }
|
70
|
+
else
|
71
|
+
it { expect(subject.inspect).to eq('#<Faraday::Error response={:status=>400}>') }
|
72
|
+
end
|
65
73
|
it { expect(subject.response_status).to eq(400) }
|
66
74
|
it { expect(subject.response_headers).to be_nil }
|
67
75
|
it { expect(subject.response_body).to be_nil }
|
@@ -27,6 +27,33 @@ RSpec.describe Faraday::ProxyOptions do
|
|
27
27
|
expect(options.inspect).to eq('#<Faraday::ProxyOptions (empty)>')
|
28
28
|
end
|
29
29
|
|
30
|
+
it 'works with hash' do
|
31
|
+
hash = { user: 'user', password: 'pass', uri: 'http://@example.org' }
|
32
|
+
options = Faraday::ProxyOptions.from(hash)
|
33
|
+
expect(options.user).to eq('user')
|
34
|
+
expect(options.password).to eq('pass')
|
35
|
+
expect(options.uri).to be_a_kind_of(URI)
|
36
|
+
expect(options.path).to eq('')
|
37
|
+
expect(options.port).to eq(80)
|
38
|
+
expect(options.host).to eq('example.org')
|
39
|
+
expect(options.scheme).to eq('http')
|
40
|
+
expect(options.inspect).to match('#<Faraday::ProxyOptions uri=')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'works with option' do
|
44
|
+
opt_arg = { user: 'user', password: 'pass', uri: 'http://@example.org' }
|
45
|
+
option = Faraday::ConnectionOptions.from(proxy: opt_arg)
|
46
|
+
options = Faraday::ProxyOptions.from(option.proxy)
|
47
|
+
expect(options.user).to eq('user')
|
48
|
+
expect(options.password).to eq('pass')
|
49
|
+
expect(options.uri).to be_a_kind_of(URI)
|
50
|
+
expect(options.path).to eq('')
|
51
|
+
expect(options.port).to eq(80)
|
52
|
+
expect(options.host).to eq('example.org')
|
53
|
+
expect(options.scheme).to eq('http')
|
54
|
+
expect(options.inspect).to match('#<Faraday::ProxyOptions uri=')
|
55
|
+
end
|
56
|
+
|
30
57
|
it 'works with no auth' do
|
31
58
|
proxy = Faraday::ProxyOptions.from 'http://example.org'
|
32
59
|
expect(proxy.user).to be_nil
|
@@ -55,6 +55,26 @@ RSpec.describe Faraday::Response::Logger do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
context 'when logger with program name' do
|
59
|
+
let(:logger) { Logger.new(string_io, progname: 'my_best_program') }
|
60
|
+
|
61
|
+
it 'logs with program name' do
|
62
|
+
conn.get '/hello'
|
63
|
+
|
64
|
+
expect(string_io.string).to match('-- my_best_program: request:')
|
65
|
+
expect(string_io.string).to match('-- my_best_program: response:')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when logger without program name' do
|
70
|
+
it 'logs without program name' do
|
71
|
+
conn.get '/hello'
|
72
|
+
|
73
|
+
expect(string_io.string).to match('-- : request:')
|
74
|
+
expect(string_io.string).to match('-- : response:')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
58
78
|
context 'with default formatter' do
|
59
79
|
let(:formatter) { instance_double(Faraday::Logging::Formatter, request: true, response: true, filter: []) }
|
60
80
|
|
@@ -169,7 +189,7 @@ RSpec.describe Faraday::Response::Logger do
|
|
169
189
|
context 'when logging request body' do
|
170
190
|
let(:logger_options) { { bodies: { request: true } } }
|
171
191
|
|
172
|
-
it '
|
192
|
+
it 'logs only request body' do
|
173
193
|
conn.post '/ohyes', 'name=Tamago', accept: 'text/html'
|
174
194
|
expect(string_io.string).to match(%(name=Tamago))
|
175
195
|
expect(string_io.string).not_to match(%(pebbles))
|
@@ -179,7 +199,7 @@ RSpec.describe Faraday::Response::Logger do
|
|
179
199
|
context 'when logging response body' do
|
180
200
|
let(:logger_options) { { bodies: { response: true } } }
|
181
201
|
|
182
|
-
it '
|
202
|
+
it 'logs only response body' do
|
183
203
|
conn.post '/ohyes', 'name=Hamachi', accept: 'text/html'
|
184
204
|
expect(string_io.string).to match(%(pebbles))
|
185
205
|
expect(string_io.string).not_to match(%(name=Hamachi))
|
@@ -189,13 +209,13 @@ RSpec.describe Faraday::Response::Logger do
|
|
189
209
|
context 'when logging request and response bodies' do
|
190
210
|
let(:logger_options) { { bodies: true } }
|
191
211
|
|
192
|
-
it '
|
212
|
+
it 'logs request and response body' do
|
193
213
|
conn.post '/ohyes', 'name=Ebi', accept: 'text/html'
|
194
214
|
expect(string_io.string).to match(%(name=Ebi))
|
195
215
|
expect(string_io.string).to match(%(pebbles))
|
196
216
|
end
|
197
217
|
|
198
|
-
it '
|
218
|
+
it 'logs response body object' do
|
199
219
|
conn.get '/rubbles', nil, accept: 'text/html'
|
200
220
|
expect(string_io.string).to match(%([\"Barney\", \"Betty\", \"Bam Bam\"]\n))
|
201
221
|
end
|
@@ -208,6 +228,21 @@ RSpec.describe Faraday::Response::Logger do
|
|
208
228
|
end
|
209
229
|
end
|
210
230
|
|
231
|
+
context 'when bodies are logged by default' do
|
232
|
+
before do
|
233
|
+
described_class.default_options = { bodies: true }
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'logs response body' do
|
237
|
+
conn.post '/ohai'
|
238
|
+
expect(string_io.string).to match(%(fred))
|
239
|
+
end
|
240
|
+
|
241
|
+
after do
|
242
|
+
described_class.default_options = { bodies: false }
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
211
246
|
context 'when logging errors' do
|
212
247
|
let(:logger_options) { { errors: true } }
|
213
248
|
|
@@ -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
|
data/spec/faraday/utils_spec.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
8
8
|
- "@iMacTia"
|
9
9
|
- "@olleolleolle"
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: faraday-net_http
|
@@ -21,7 +20,7 @@ dependencies:
|
|
21
20
|
version: '2.0'
|
22
21
|
- - "<"
|
23
22
|
- !ruby/object:Gem::Version
|
24
|
-
version: '3.
|
23
|
+
version: '3.5'
|
25
24
|
type: :runtime
|
26
25
|
prerelease: false
|
27
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +30,21 @@ dependencies:
|
|
31
30
|
version: '2.0'
|
32
31
|
- - "<"
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: '3.
|
33
|
+
version: '3.5'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: json
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: logger
|
37
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +59,6 @@ dependencies:
|
|
46
59
|
- - ">="
|
47
60
|
- !ruby/object:Gem::Version
|
48
61
|
version: '0'
|
49
|
-
description:
|
50
62
|
email: technoweenie@gmail.com
|
51
63
|
executables: []
|
52
64
|
extensions: []
|
@@ -132,10 +144,10 @@ licenses:
|
|
132
144
|
- MIT
|
133
145
|
metadata:
|
134
146
|
homepage_uri: https://lostisland.github.io/faraday
|
135
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
147
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.13.1
|
136
148
|
source_code_uri: https://github.com/lostisland/faraday
|
137
149
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
138
|
-
|
150
|
+
rubygems_mfa_required: 'true'
|
139
151
|
rdoc_options: []
|
140
152
|
require_paths:
|
141
153
|
- lib
|
@@ -151,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
163
|
- !ruby/object:Gem::Version
|
152
164
|
version: '0'
|
153
165
|
requirements: []
|
154
|
-
rubygems_version: 3.
|
155
|
-
signing_key:
|
166
|
+
rubygems_version: 3.6.7
|
156
167
|
specification_version: 4
|
157
168
|
summary: HTTP/REST API client library.
|
158
169
|
test_files: []
|