faraday 2.7.4 → 2.7.5
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 +1 -1
- data/lib/faraday/connection.rb +11 -16
- data/lib/faraday/logging/formatter.rb +1 -1
- data/lib/faraday/options/connection_options.rb +7 -6
- data/lib/faraday/options/env.rb +67 -68
- data/lib/faraday/options/proxy_options.rb +7 -3
- data/lib/faraday/options/request_options.rb +7 -6
- data/lib/faraday/options/ssl_options.rb +51 -50
- data/lib/faraday/request/instrumentation.rb +1 -1
- data/lib/faraday/request/json.rb +10 -1
- data/lib/faraday/request.rb +8 -7
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/options/options_spec.rb +1 -1
- data/spec/faraday/options/proxy_options_spec.rb +8 -0
- data/spec/faraday/request/json_spec.rb +24 -0
- 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: ddb207e6f8b639db4a4f162edd714b008e84ba8a967dc2c94977aaea1d87e7fe
|
4
|
+
data.tar.gz: 6e624ee223ee7322caa02e03faf735ff5733eafefeb2d1f289388211228ea42b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218f458603cb4401eb89ac7fa4300cd34f8aadc41325d31e63f05b6ffe6e4a94c6408f3a0dcbb738b7ab9a7cafce373f6b3f0d4be8ea0c044d9c87eeae5b9a52
|
7
|
+
data.tar.gz: b6859a02105b9ea6559dc6fd54554c3c035a1b135e7e7dbcc842325273a3ba7ca0bcdf477d9ec3185a7e016ab0e1ad85debb87c978484113691aa7888fe85a35
|
data/lib/faraday/adapter/test.rb
CHANGED
@@ -184,7 +184,7 @@ module Faraday
|
|
184
184
|
end
|
185
185
|
|
186
186
|
# Stub request
|
187
|
-
|
187
|
+
Stub = Struct.new(:host, :path, :query, :headers, :body, :strict_mode, :block) do
|
188
188
|
# @param env [Faraday::Env]
|
189
189
|
def matches?(env)
|
190
190
|
request_host = env[:url].host
|
data/lib/faraday/connection.rb
CHANGED
@@ -514,22 +514,17 @@ module Faraday
|
|
514
514
|
return if Faraday.ignore_env_proxy
|
515
515
|
|
516
516
|
uri = nil
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
when nil
|
529
|
-
uri = find_default_proxy
|
530
|
-
end
|
531
|
-
else
|
532
|
-
warn 'no_proxy is unsupported' if ENV['no_proxy'] || ENV['NO_PROXY']
|
517
|
+
case url
|
518
|
+
when String
|
519
|
+
uri = Utils.URI(url)
|
520
|
+
uri = if uri.host.nil?
|
521
|
+
find_default_proxy
|
522
|
+
else
|
523
|
+
URI.parse("#{uri.scheme}://#{uri.host}").find_proxy
|
524
|
+
end
|
525
|
+
when URI
|
526
|
+
uri = url.find_proxy
|
527
|
+
when nil
|
533
528
|
uri = find_default_proxy
|
534
529
|
end
|
535
530
|
ProxyOptions.from(uri) if uri
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Faraday
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
# @!parse
|
5
|
+
# # ConnectionOptions contains the configurable properties for a Faraday
|
6
|
+
# # connection object.
|
7
|
+
# class ConnectionOptions < Options; end
|
8
|
+
ConnectionOptions = Options.new(:request, :proxy, :ssl, :builder, :url,
|
9
|
+
:parallel_manager, :params, :headers,
|
10
|
+
:builder_class) do
|
10
11
|
options request: RequestOptions, ssl: SSLOptions
|
11
12
|
|
12
13
|
memoized(:request) { self.class.options_for(:request).new }
|
data/lib/faraday/options/env.rb
CHANGED
@@ -1,71 +1,70 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Faraday
|
4
|
-
# @!
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# - `:
|
28
|
-
#
|
29
|
-
# - `:
|
30
|
-
# - `:
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
ContentLength
|
62
|
-
StatusesWithoutBody
|
63
|
-
SuccessfulStatuses
|
64
|
-
# rubocop:enable Naming/ConstantName
|
4
|
+
# @!parse
|
5
|
+
# # @!attribute method
|
6
|
+
# # @return [Symbol] HTTP method (`:get`, `:post`)
|
7
|
+
# #
|
8
|
+
# # @!attribute body
|
9
|
+
# # @return [String] The request body that will eventually be converted to a
|
10
|
+
# # string.
|
11
|
+
# #
|
12
|
+
# # @!attribute url
|
13
|
+
# # @return [URI] URI instance for the current request.
|
14
|
+
# #
|
15
|
+
# # @!attribute request
|
16
|
+
# # @return [Hash] options for configuring the request.
|
17
|
+
# # Options for configuring the request.
|
18
|
+
# #
|
19
|
+
# # - `:timeout` - time limit for the entire request (Integer in
|
20
|
+
# # seconds)
|
21
|
+
# # - `:open_timeout` - time limit for just the connection phase (e.g.
|
22
|
+
# # handshake) (Integer in seconds)
|
23
|
+
# # - `:read_timeout` - time limit for the first response byte received from
|
24
|
+
# # the server (Integer in seconds)
|
25
|
+
# # - `:write_timeout` - time limit for the client to send the request to the
|
26
|
+
# # server (Integer in seconds)
|
27
|
+
# # - `:on_data` - Proc for streaming
|
28
|
+
# # - `:proxy` - Hash of proxy options
|
29
|
+
# # - `:uri` - Proxy server URI
|
30
|
+
# # - `:user` - Proxy server username
|
31
|
+
# # - `:password` - Proxy server password
|
32
|
+
# #
|
33
|
+
# # @!attribute request_headers
|
34
|
+
# # @return [Hash] HTTP Headers to be sent to the server.
|
35
|
+
# #
|
36
|
+
# # @!attribute ssl
|
37
|
+
# # @return [Hash] options for configuring SSL requests
|
38
|
+
# #
|
39
|
+
# # @!attribute parallel_manager
|
40
|
+
# # @return [Object] sent if the connection is in parallel mode
|
41
|
+
# #
|
42
|
+
# # @!attribute params
|
43
|
+
# # @return [Hash]
|
44
|
+
# #
|
45
|
+
# # @!attribute response
|
46
|
+
# # @return [Response]
|
47
|
+
# #
|
48
|
+
# # @!attribute response_headers
|
49
|
+
# # @return [Hash] HTTP headers from the server
|
50
|
+
# #
|
51
|
+
# # @!attribute status
|
52
|
+
# # @return [Integer] HTTP response status code
|
53
|
+
# #
|
54
|
+
# # @!attribute reason_phrase
|
55
|
+
# # @return [String]
|
56
|
+
# class Env < Options; end
|
57
|
+
Env = Options.new(:method, :request_body, :url, :request,
|
58
|
+
:request_headers, :ssl, :parallel_manager, :params,
|
59
|
+
:response, :response_headers, :status,
|
60
|
+
:reason_phrase, :response_body) do
|
61
|
+
const_set(:ContentLength, 'Content-Length')
|
62
|
+
const_set(:StatusesWithoutBody, Set.new([204, 304]))
|
63
|
+
const_set(:SuccessfulStatuses, (200..299).freeze)
|
65
64
|
|
66
65
|
# A Set of HTTP verbs that typically send a body. If no body is set for
|
67
66
|
# these requests, the Content-Length header is set to 0.
|
68
|
-
MethodsWithBodies
|
67
|
+
const_set(:MethodsWithBodies, Set.new(Faraday::METHODS_WITH_BODY.map(&:to_sym)))
|
69
68
|
|
70
69
|
options request: RequestOptions,
|
71
70
|
request_headers: Utils::Headers, response_headers: Utils::Headers
|
@@ -126,25 +125,25 @@ module Faraday
|
|
126
125
|
|
127
126
|
# @return [Boolean] true if status is in the set of {SuccessfulStatuses}.
|
128
127
|
def success?
|
129
|
-
SuccessfulStatuses.include?(status)
|
128
|
+
Env::SuccessfulStatuses.include?(status)
|
130
129
|
end
|
131
130
|
|
132
131
|
# @return [Boolean] true if there's no body yet, and the method is in the
|
133
|
-
# set of {MethodsWithBodies}.
|
132
|
+
# set of {Env::MethodsWithBodies}.
|
134
133
|
def needs_body?
|
135
|
-
!body && MethodsWithBodies.include?(method)
|
134
|
+
!body && Env::MethodsWithBodies.include?(method)
|
136
135
|
end
|
137
136
|
|
138
137
|
# Sets content length to zero and the body to the empty string.
|
139
138
|
def clear_body
|
140
|
-
request_headers[ContentLength] = '0'
|
139
|
+
request_headers[Env::ContentLength] = '0'
|
141
140
|
self.body = +''
|
142
141
|
end
|
143
142
|
|
144
143
|
# @return [Boolean] true if the status isn't in the set of
|
145
|
-
# {StatusesWithoutBody}.
|
144
|
+
# {Env::StatusesWithoutBody}.
|
146
145
|
def parse_body?
|
147
|
-
!StatusesWithoutBody.include?(status)
|
146
|
+
!Env::StatusesWithoutBody.include?(status)
|
148
147
|
end
|
149
148
|
|
150
149
|
# @return [Boolean] true if there is a parallel_manager
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Faraday
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
4
|
+
# @!parse
|
5
|
+
# # ProxyOptions contains the configurable properties for the proxy
|
6
|
+
# # configuration used when making an HTTP request.
|
7
|
+
# class ProxyOptions < Options; end
|
8
|
+
ProxyOptions = Options.new(:uri, :user, :password) do
|
7
9
|
extend Forwardable
|
8
10
|
def_delegators :uri, :scheme, :scheme=, :host, :host=, :port, :port=,
|
9
11
|
:path, :path=
|
10
12
|
|
11
13
|
def self.from(value)
|
12
14
|
case value
|
15
|
+
when ''
|
16
|
+
value = nil
|
13
17
|
when String
|
14
18
|
# URIs without a scheme should default to http (like 'example:123').
|
15
19
|
# This fixes #1282 and prevents a silent failure in some adapters.
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Faraday
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
# @!parse
|
5
|
+
# # RequestOptions contains the configurable properties for a Faraday request.
|
6
|
+
# class RequestOptions < Options; end
|
7
|
+
RequestOptions = Options.new(:params_encoder, :proxy, :bind,
|
8
|
+
:timeout, :open_timeout, :read_timeout,
|
9
|
+
:write_timeout, :boundary, :oauth,
|
10
|
+
:context, :on_data) do
|
10
11
|
def []=(key, value)
|
11
12
|
if key && key.to_sym == :proxy
|
12
13
|
super(key, value ? ProxyOptions.from(value) : nil)
|
@@ -1,56 +1,57 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Faraday
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
4
|
+
# @!parse
|
5
|
+
# # SSL-related options.
|
6
|
+
# #
|
7
|
+
# # @!attribute verify
|
8
|
+
# # @return [Boolean] whether to verify SSL certificates or not
|
9
|
+
# #
|
10
|
+
# # @!attribute verify_hostname
|
11
|
+
# # @return [Boolean] whether to enable hostname verification on server certificates
|
12
|
+
# # during the handshake or not (see https://github.com/ruby/openssl/pull/60)
|
13
|
+
# #
|
14
|
+
# # @!attribute ca_file
|
15
|
+
# # @return [String] CA file
|
16
|
+
# #
|
17
|
+
# # @!attribute ca_path
|
18
|
+
# # @return [String] CA path
|
19
|
+
# #
|
20
|
+
# # @!attribute verify_mode
|
21
|
+
# # @return [Integer] Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
|
22
|
+
# #
|
23
|
+
# # @!attribute cert_store
|
24
|
+
# # @return [OpenSSL::X509::Store] certificate store
|
25
|
+
# #
|
26
|
+
# # @!attribute client_cert
|
27
|
+
# # @return [String, OpenSSL::X509::Certificate] client certificate
|
28
|
+
# #
|
29
|
+
# # @!attribute client_key
|
30
|
+
# # @return [String, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] client key
|
31
|
+
# #
|
32
|
+
# # @!attribute certificate
|
33
|
+
# # @return [OpenSSL::X509::Certificate] certificate (Excon only)
|
34
|
+
# #
|
35
|
+
# # @!attribute private_key
|
36
|
+
# # @return [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] private key (Excon only)
|
37
|
+
# #
|
38
|
+
# # @!attribute verify_depth
|
39
|
+
# # @return [Integer] maximum depth for the certificate chain verification
|
40
|
+
# #
|
41
|
+
# # @!attribute version
|
42
|
+
# # @return [String, Symbol] SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-ssl_version-3D)
|
43
|
+
# #
|
44
|
+
# # @!attribute min_version
|
45
|
+
# # @return [String, Symbol] minimum SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-min_version-3D)
|
46
|
+
# #
|
47
|
+
# # @!attribute max_version
|
48
|
+
# # @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)
|
49
|
+
# class SSLOptions < Options; end
|
50
|
+
SSLOptions = Options.new(:verify, :verify_hostname,
|
51
|
+
:ca_file, :ca_path, :verify_mode,
|
52
|
+
:cert_store, :client_cert, :client_key,
|
53
|
+
:certificate, :private_key, :verify_depth,
|
54
|
+
:version, :min_version, :max_version) do
|
54
55
|
# @return [Boolean] true if should verify
|
55
56
|
def verify?
|
56
57
|
verify != false
|
@@ -5,7 +5,7 @@ module Faraday
|
|
5
5
|
# Middleware for instrumenting Requests.
|
6
6
|
class Instrumentation < Faraday::Middleware
|
7
7
|
# Options class used in Request::Instrumentation class.
|
8
|
-
|
8
|
+
Options = Faraday::Options.new(:name, :instrumenter) do
|
9
9
|
# @return [String]
|
10
10
|
def name
|
11
11
|
self[:name] ||= 'request.faraday'
|
data/lib/faraday/request/json.rb
CHANGED
@@ -40,7 +40,16 @@ module Faraday
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def body?(env)
|
43
|
-
|
43
|
+
body = env[:body]
|
44
|
+
case body
|
45
|
+
when true, false
|
46
|
+
true
|
47
|
+
when nil
|
48
|
+
# NOTE: nil can be converted to `"null"`, but this middleware doesn't process `nil` for the compatibility.
|
49
|
+
false
|
50
|
+
else
|
51
|
+
!(body.respond_to?(:to_str) && body.empty?)
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
def request_type(env)
|
data/lib/faraday/request.rb
CHANGED
@@ -24,13 +24,14 @@ module Faraday
|
|
24
24
|
# @return [String] body
|
25
25
|
# @!attribute options
|
26
26
|
# @return [RequestOptions] options
|
27
|
-
|
28
|
-
# rubocop:disable Style/StructInheritance
|
29
|
-
class Request < Struct.new(:http_method, :path, :params, :headers, :body, :options)
|
30
|
-
# rubocop:enable Style/StructInheritance
|
31
|
-
|
27
|
+
Request = Struct.new(:http_method, :path, :params, :headers, :body, :options) do
|
32
28
|
extend MiddlewareRegistry
|
33
29
|
|
30
|
+
alias_method :member_get, :[]
|
31
|
+
private :member_get
|
32
|
+
alias_method :member_set, :[]=
|
33
|
+
private :member_set
|
34
|
+
|
34
35
|
# @param request_method [String]
|
35
36
|
# @yield [request] for block customization, if block given
|
36
37
|
# @yieldparam request [Request]
|
@@ -48,7 +49,7 @@ module Faraday
|
|
48
49
|
if params
|
49
50
|
params.replace hash
|
50
51
|
else
|
51
|
-
|
52
|
+
member_set(:params, hash)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -59,7 +60,7 @@ module Faraday
|
|
59
60
|
if headers
|
60
61
|
headers.replace hash
|
61
62
|
else
|
62
|
-
|
63
|
+
member_set(:headers, hash)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
data/lib/faraday/version.rb
CHANGED
@@ -32,6 +32,14 @@ RSpec.describe Faraday::ProxyOptions do
|
|
32
32
|
expect(proxy.user).to be_nil
|
33
33
|
expect(proxy.password).to be_nil
|
34
34
|
end
|
35
|
+
|
36
|
+
it 'treats empty string as nil' do
|
37
|
+
proxy = nil
|
38
|
+
proxy_string = proxy.to_s # => empty string
|
39
|
+
options = Faraday::ProxyOptions.from proxy_string
|
40
|
+
expect(options).to be_a_kind_of(Faraday::ProxyOptions)
|
41
|
+
expect(options.inspect).to eq('#<Faraday::ProxyOptions (empty)>')
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
it 'allows hash access' do
|
@@ -73,6 +73,30 @@ RSpec.describe Faraday::Request::Json do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
context 'true body' do
|
77
|
+
let(:result) { process(true) }
|
78
|
+
|
79
|
+
it 'encodes body' do
|
80
|
+
expect(result_body).to eq('true')
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'adds content type' do
|
84
|
+
expect(result_type).to eq('application/json')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'false body' do
|
89
|
+
let(:result) { process(false) }
|
90
|
+
|
91
|
+
it 'encodes body' do
|
92
|
+
expect(result_body).to eq('false')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'adds content type' do
|
96
|
+
expect(result_type).to eq('application/json')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
76
100
|
context 'object body with json type' do
|
77
101
|
let(:result) { process({ a: 1 }, 'application/json; charset=utf-8') }
|
78
102
|
|
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.5
|
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: 2023-
|
13
|
+
date: 2023-05-23 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.5
|
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:
|