faraday 2.12.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/lib/faraday/logging/formatter.rb +6 -6
- data/lib/faraday/options/env.rb +1 -1
- data/lib/faraday/options/proxy_options.rb +4 -2
- data/lib/faraday/options/ssl_options.rb +4 -1
- data/lib/faraday/rack_builder.rb +20 -19
- data/lib/faraday/response/logger.rb +5 -3
- 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/utils_spec.rb +1 -0
- metadata +6 -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
|
@@ -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/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
|
# #
|
@@ -50,7 +53,7 @@ module Faraday
|
|
50
53
|
# # @!attribute ciphers
|
51
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)
|
52
55
|
# class SSLOptions < Options; end
|
53
|
-
SSLOptions = Options.new(:verify, :verify_hostname,
|
56
|
+
SSLOptions = Options.new(:verify, :verify_hostname, :hostname,
|
54
57
|
:ca_file, :ca_path, :verify_mode,
|
55
58
|
:cert_store, :client_cert, :client_key,
|
56
59
|
:certificate, :private_key, :verify_depth,
|
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
|
|
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
|
|
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,7 @@ dependencies:
|
|
31
30
|
version: '2.0'
|
32
31
|
- - "<"
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: '3.
|
33
|
+
version: '3.5'
|
35
34
|
- !ruby/object:Gem::Dependency
|
36
35
|
name: json
|
37
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,7 +59,6 @@ dependencies:
|
|
60
59
|
- - ">="
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: '0'
|
63
|
-
description:
|
64
62
|
email: technoweenie@gmail.com
|
65
63
|
executables: []
|
66
64
|
extensions: []
|
@@ -146,11 +144,10 @@ licenses:
|
|
146
144
|
- MIT
|
147
145
|
metadata:
|
148
146
|
homepage_uri: https://lostisland.github.io/faraday
|
149
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
147
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.13.1
|
150
148
|
source_code_uri: https://github.com/lostisland/faraday
|
151
149
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
152
150
|
rubygems_mfa_required: 'true'
|
153
|
-
post_install_message:
|
154
151
|
rdoc_options: []
|
155
152
|
require_paths:
|
156
153
|
- lib
|
@@ -166,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
163
|
- !ruby/object:Gem::Version
|
167
164
|
version: '0'
|
168
165
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
-
signing_key:
|
166
|
+
rubygems_version: 3.6.7
|
171
167
|
specification_version: 4
|
172
168
|
summary: HTTP/REST API client library.
|
173
169
|
test_files: []
|