faraday 0.17.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -8
- data/LICENSE.md +1 -1
- data/README.md +18 -358
- data/Rakefile +1 -7
- data/examples/client_spec.rb +65 -0
- data/examples/client_test.rb +79 -0
- data/lib/faraday.rb +94 -175
- data/lib/faraday/adapter.rb +82 -22
- data/lib/faraday/adapter/em_http.rb +142 -99
- data/lib/faraday/adapter/em_http_ssl_patch.rb +24 -18
- data/lib/faraday/adapter/em_synchrony.rb +104 -60
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
- data/lib/faraday/adapter/excon.rb +98 -56
- data/lib/faraday/adapter/httpclient.rb +83 -59
- data/lib/faraday/adapter/net_http.rb +130 -63
- data/lib/faraday/adapter/net_http_persistent.rb +50 -27
- data/lib/faraday/adapter/patron.rb +80 -43
- data/lib/faraday/adapter/rack.rb +30 -13
- data/lib/faraday/adapter/test.rb +86 -53
- data/lib/faraday/adapter/typhoeus.rb +4 -1
- data/lib/faraday/adapter_registry.rb +30 -0
- data/lib/faraday/autoload.rb +47 -36
- data/lib/faraday/connection.rb +312 -182
- data/lib/faraday/dependency_loader.rb +37 -0
- data/lib/faraday/encoders/flat_params_encoder.rb +98 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +171 -0
- data/lib/faraday/error.rb +9 -35
- data/lib/faraday/file_part.rb +128 -0
- data/lib/faraday/logging/formatter.rb +105 -0
- data/lib/faraday/middleware.rb +12 -28
- data/lib/faraday/middleware_registry.rb +129 -0
- data/lib/faraday/options.rb +32 -183
- data/lib/faraday/options/connection_options.rb +22 -0
- data/lib/faraday/options/env.rb +181 -0
- data/lib/faraday/options/proxy_options.rb +28 -0
- data/lib/faraday/options/request_options.rb +22 -0
- data/lib/faraday/options/ssl_options.rb +59 -0
- data/lib/faraday/param_part.rb +53 -0
- data/lib/faraday/parameters.rb +4 -197
- data/lib/faraday/rack_builder.rb +66 -55
- data/lib/faraday/request.rb +68 -36
- data/lib/faraday/request/authorization.rb +44 -30
- data/lib/faraday/request/basic_authentication.rb +14 -7
- data/lib/faraday/request/instrumentation.rb +45 -27
- data/lib/faraday/request/multipart.rb +79 -48
- data/lib/faraday/request/retry.rb +197 -171
- data/lib/faraday/request/token_authentication.rb +15 -10
- data/lib/faraday/request/url_encoded.rb +43 -23
- data/lib/faraday/response.rb +24 -14
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +38 -18
- data/lib/faraday/utils.rb +36 -245
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/spec/faraday/adapter/em_http_spec.rb +47 -0
- data/spec/faraday/adapter/em_synchrony_spec.rb +16 -0
- data/spec/faraday/adapter/excon_spec.rb +49 -0
- data/spec/faraday/adapter/httpclient_spec.rb +73 -0
- data/spec/faraday/adapter/net_http_persistent_spec.rb +57 -0
- data/spec/faraday/adapter/net_http_spec.rb +64 -0
- data/spec/faraday/adapter/patron_spec.rb +18 -0
- data/spec/faraday/adapter/rack_spec.rb +8 -0
- data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/composite_read_io_spec.rb +80 -0
- data/spec/faraday/connection_spec.rb +691 -0
- data/spec/faraday/error_spec.rb +0 -57
- data/spec/faraday/middleware_spec.rb +26 -0
- data/spec/faraday/options/env_spec.rb +70 -0
- data/spec/faraday/options/options_spec.rb +297 -0
- data/spec/faraday/options/proxy_options_spec.rb +37 -0
- data/spec/faraday/options/request_options_spec.rb +19 -0
- data/spec/faraday/params_encoders/flat_spec.rb +34 -0
- data/spec/faraday/params_encoders/nested_spec.rb +134 -0
- data/spec/faraday/rack_builder_spec.rb +196 -0
- data/spec/faraday/request/authorization_spec.rb +88 -0
- data/spec/faraday/request/instrumentation_spec.rb +76 -0
- data/spec/faraday/request/multipart_spec.rb +274 -0
- data/spec/faraday/request/retry_spec.rb +242 -0
- data/spec/faraday/request/url_encoded_spec.rb +83 -0
- data/spec/faraday/request_spec.rb +109 -0
- data/spec/faraday/response/logger_spec.rb +220 -0
- data/spec/faraday/response/middleware_spec.rb +68 -0
- data/spec/faraday/response/raise_error_spec.rb +15 -15
- data/spec/faraday/response_spec.rb +75 -0
- data/spec/faraday/utils/headers_spec.rb +82 -0
- data/spec/faraday/utils_spec.rb +56 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +63 -36
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +133 -0
- data/spec/support/shared_examples/adapter.rb +104 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +234 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- data/spec/support/webmock_rack_app.rb +68 -0
- metadata +66 -38
- data/lib/faraday/deprecate.rb +0 -107
- data/lib/faraday/upload_io.rb +0 -67
- data/spec/faraday/deprecate_spec.rb +0 -69
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -30
- data/test/adapters/em_synchrony_test.rb +0 -32
- data/test/adapters/excon_test.rb +0 -30
- data/test/adapters/httpclient_test.rb +0 -34
- data/test/adapters/integration.rb +0 -263
- data/test/adapters/logger_test.rb +0 -136
- data/test/adapters/net_http_persistent_test.rb +0 -114
- data/test/adapters/net_http_test.rb +0 -79
- data/test/adapters/patron_test.rb +0 -40
- data/test/adapters/rack_test.rb +0 -38
- data/test/adapters/test_middleware_test.rb +0 -157
- data/test/adapters/typhoeus_test.rb +0 -38
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -109
- data/test/connection_test.rb +0 -738
- data/test/env_test.rb +0 -268
- data/test/helper.rb +0 -75
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -282
- data/test/middleware_stack_test.rb +0 -260
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -333
- data/test/parameters_test.rb +0 -157
- data/test/request_middleware_test.rb +0 -126
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -98
@@ -1,78 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Faraday
|
2
4
|
class Adapter
|
5
|
+
# HTTPClient adapter.
|
3
6
|
class HTTPClient < Faraday::Adapter
|
4
7
|
dependency 'httpclient'
|
5
8
|
|
6
|
-
def
|
7
|
-
@client ||= ::HTTPClient.new
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
super
|
12
|
-
|
13
|
-
# enable compression
|
14
|
-
client.transparent_gzip_decompression = true
|
9
|
+
def build_connection(env)
|
10
|
+
@client ||= ::HTTPClient.new.tap do |cli|
|
11
|
+
# enable compression
|
12
|
+
cli.transparent_gzip_decompression = true
|
13
|
+
end
|
15
14
|
|
16
|
-
if req = env[:request]
|
17
|
-
if proxy = req[:proxy]
|
18
|
-
configure_proxy proxy
|
15
|
+
if (req = env[:request])
|
16
|
+
if (proxy = req[:proxy])
|
17
|
+
configure_proxy @client, proxy
|
19
18
|
end
|
20
19
|
|
21
|
-
if bind = req[:bind]
|
22
|
-
configure_socket bind
|
20
|
+
if (bind = req[:bind])
|
21
|
+
configure_socket @client, bind
|
23
22
|
end
|
24
23
|
|
25
|
-
configure_timeouts req
|
24
|
+
configure_timeouts @client, req
|
26
25
|
end
|
27
26
|
|
28
|
-
if env[:url].scheme == 'https' && ssl = env[:ssl]
|
29
|
-
configure_ssl ssl
|
27
|
+
if env[:url].scheme == 'https' && (ssl = env[:ssl])
|
28
|
+
configure_ssl @client, ssl
|
30
29
|
end
|
31
30
|
|
32
|
-
configure_client
|
31
|
+
configure_client @client
|
32
|
+
|
33
|
+
@client
|
34
|
+
end
|
33
35
|
|
34
|
-
|
36
|
+
def call(env)
|
37
|
+
super
|
38
|
+
|
39
|
+
# TODO: Don't stream yet.
|
35
40
|
# https://github.com/nahi/httpclient/pull/90
|
36
41
|
env[:body] = env[:body].read if env[:body].respond_to? :read
|
37
42
|
|
38
|
-
|
39
|
-
:
|
40
|
-
|
43
|
+
connection(env) do |http|
|
44
|
+
resp = http.request env[:method], env[:url],
|
45
|
+
body: env[:body],
|
46
|
+
header: env[:request_headers]
|
41
47
|
|
42
|
-
|
48
|
+
if (req = env[:request]).stream_response?
|
49
|
+
warn "Streaming downloads for #{self.class.name} " \
|
50
|
+
'are not yet implemented.'
|
51
|
+
req.on_data.call(resp.body, resp.body.bytesize)
|
52
|
+
end
|
53
|
+
save_response env, resp.status, resp.body, resp.headers, resp.reason
|
43
54
|
|
44
|
-
|
55
|
+
@app.call env
|
56
|
+
end
|
45
57
|
rescue ::HTTPClient::TimeoutError, Errno::ETIMEDOUT
|
46
|
-
raise Faraday::TimeoutError,
|
47
|
-
rescue ::HTTPClient::BadResponseError =>
|
48
|
-
if
|
49
|
-
raise Faraday::ConnectionFailed,
|
50
|
-
|
51
|
-
raise Faraday::ClientError, $!
|
58
|
+
raise Faraday::TimeoutError, $ERROR_INFO
|
59
|
+
rescue ::HTTPClient::BadResponseError => e
|
60
|
+
if e.message.include?('status 407')
|
61
|
+
raise Faraday::ConnectionFailed,
|
62
|
+
%(407 "Proxy Authentication Required ")
|
52
63
|
end
|
53
|
-
|
54
|
-
raise Faraday::
|
55
|
-
rescue
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
|
65
|
+
raise Faraday::ClientError, $ERROR_INFO
|
66
|
+
rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED, IOError, SocketError
|
67
|
+
raise Faraday::ConnectionFailed, $ERROR_INFO
|
68
|
+
rescue StandardError => e
|
69
|
+
if defined?(::OpenSSL::SSL::SSLError) && \
|
70
|
+
e.is_a?(::OpenSSL::SSL::SSLError)
|
71
|
+
raise Faraday::SSLError, e
|
60
72
|
end
|
73
|
+
|
74
|
+
raise
|
61
75
|
end
|
62
76
|
|
63
|
-
|
77
|
+
# @param bind [Hash]
|
78
|
+
def configure_socket(client, bind)
|
64
79
|
client.socket_local.host = bind[:host]
|
65
80
|
client.socket_local.port = bind[:port]
|
66
81
|
end
|
67
82
|
|
68
|
-
|
83
|
+
# Configure proxy URI and any user credentials.
|
84
|
+
#
|
85
|
+
# @param proxy [Hash]
|
86
|
+
def configure_proxy(client, proxy)
|
69
87
|
client.proxy = proxy[:uri]
|
70
|
-
|
71
|
-
|
72
|
-
|
88
|
+
return unless proxy[:user] && proxy[:password]
|
89
|
+
|
90
|
+
client.set_proxy_auth(proxy[:user], proxy[:password])
|
73
91
|
end
|
74
92
|
|
75
|
-
|
93
|
+
# @param ssl [Hash]
|
94
|
+
def configure_ssl(client, ssl)
|
76
95
|
ssl_config = client.ssl_config
|
77
96
|
ssl_config.verify_mode = ssl_verify_mode(ssl)
|
78
97
|
ssl_config.cert_store = ssl_cert_store(ssl)
|
@@ -84,40 +103,45 @@ module Faraday
|
|
84
103
|
ssl_config.verify_depth = ssl[:verify_depth] if ssl[:verify_depth]
|
85
104
|
end
|
86
105
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
client.
|
91
|
-
client.send_timeout = req[:timeout]
|
106
|
+
# @param req [Hash]
|
107
|
+
def configure_timeouts(client, req)
|
108
|
+
if (sec = request_timeout(:open, req))
|
109
|
+
client.connect_timeout = sec
|
92
110
|
end
|
93
111
|
|
94
|
-
if req
|
95
|
-
client.
|
96
|
-
client.send_timeout = req[:open_timeout]
|
112
|
+
if (sec = request_timeout(:write, req))
|
113
|
+
client.send_timeout = sec
|
97
114
|
end
|
115
|
+
|
116
|
+
return unless (sec = request_timeout(:read, req))
|
117
|
+
|
118
|
+
client.receive_timeout = sec
|
98
119
|
end
|
99
120
|
|
100
|
-
def configure_client
|
101
|
-
@config_block
|
121
|
+
def configure_client(client)
|
122
|
+
@config_block&.call(client)
|
102
123
|
end
|
103
124
|
|
125
|
+
# @param ssl [Hash]
|
126
|
+
# @return [OpenSSL::X509::Store]
|
104
127
|
def ssl_cert_store(ssl)
|
105
128
|
return ssl[:cert_store] if ssl[:cert_store]
|
129
|
+
|
106
130
|
# Memoize the cert store so that the same one is passed to
|
107
|
-
# HTTPClient each time, to avoid resyncing SSL
|
131
|
+
# HTTPClient each time, to avoid resyncing SSL sessions when
|
108
132
|
# it's changed
|
109
|
-
@
|
133
|
+
@ssl_cert_store ||= begin
|
110
134
|
# Use the default cert store by default, i.e. system ca certs
|
111
|
-
|
112
|
-
cert_store.set_default_paths
|
113
|
-
cert_store
|
135
|
+
OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
114
136
|
end
|
115
137
|
end
|
116
138
|
|
139
|
+
# @param ssl [Hash]
|
117
140
|
def ssl_verify_mode(ssl)
|
118
141
|
ssl[:verify_mode] || begin
|
119
142
|
if ssl.fetch(:verify, true)
|
120
|
-
OpenSSL::SSL::VERIFY_PEER |
|
143
|
+
OpenSSL::SSL::VERIFY_PEER |
|
144
|
+
OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
121
145
|
else
|
122
146
|
OpenSSL::SSL::VERIFY_NONE
|
123
147
|
end
|
@@ -1,16 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'net/https'
|
3
5
|
rescue LoadError
|
4
|
-
warn
|
6
|
+
warn 'Warning: no such file to load -- net/https. ' \
|
7
|
+
'Make sure openssl is installed if you want ssl support'
|
5
8
|
require 'net/http'
|
6
9
|
end
|
7
10
|
require 'zlib'
|
8
11
|
|
9
12
|
module Faraday
|
10
13
|
class Adapter
|
14
|
+
# Net::HTTP adapter.
|
11
15
|
class NetHttp < Faraday::Adapter
|
12
|
-
|
16
|
+
exceptions = [
|
13
17
|
IOError,
|
18
|
+
Errno::EADDRNOTAVAIL,
|
14
19
|
Errno::ECONNABORTED,
|
15
20
|
Errno::ECONNREFUSED,
|
16
21
|
Errno::ECONNRESET,
|
@@ -22,54 +27,78 @@ module Faraday
|
|
22
27
|
Net::HTTPHeaderSyntaxError,
|
23
28
|
Net::ProtocolError,
|
24
29
|
SocketError,
|
25
|
-
Zlib::GzipFile::Error
|
30
|
+
Zlib::GzipFile::Error
|
26
31
|
]
|
27
32
|
|
28
|
-
|
29
|
-
|
33
|
+
if defined?(::OpenSSL::SSL::SSLError)
|
34
|
+
exceptions << ::OpenSSL::SSL::SSLError
|
35
|
+
end
|
36
|
+
exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)
|
37
|
+
|
38
|
+
NET_HTTP_EXCEPTIONS = exceptions.freeze
|
30
39
|
|
31
40
|
def initialize(app = nil, opts = {}, &block)
|
32
|
-
@
|
41
|
+
@ssl_cert_store = nil
|
33
42
|
super(app, opts, &block)
|
34
43
|
end
|
35
44
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
45
|
+
def build_connection(env)
|
46
|
+
net_http_connection(env).tap do |http|
|
47
|
+
if http.respond_to?(:use_ssl=)
|
48
|
+
http.use_ssl = env[:url].scheme == 'https'
|
49
|
+
end
|
50
|
+
configure_ssl(http, env[:ssl])
|
40
51
|
configure_request(http, env[:request])
|
52
|
+
end
|
53
|
+
end
|
41
54
|
|
55
|
+
def net_http_connection(env)
|
56
|
+
klass = if (proxy = env[:request][:proxy])
|
57
|
+
Net::HTTP::Proxy(proxy[:uri].hostname, proxy[:uri].port,
|
58
|
+
proxy[:user], proxy[:password])
|
59
|
+
else
|
60
|
+
Net::HTTP
|
61
|
+
end
|
62
|
+
port = env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)
|
63
|
+
klass.new(env[:url].hostname, port)
|
64
|
+
end
|
65
|
+
|
66
|
+
def call(env)
|
67
|
+
super
|
68
|
+
http_response = connection(env) do |http|
|
42
69
|
begin
|
43
|
-
|
44
|
-
rescue *NET_HTTP_EXCEPTIONS =>
|
45
|
-
if defined?(OpenSSL) && OpenSSL::SSL::SSLError
|
46
|
-
raise Faraday::SSLError,
|
47
|
-
else
|
48
|
-
raise Faraday::ConnectionFailed, err
|
70
|
+
perform_request(http, env)
|
71
|
+
rescue *NET_HTTP_EXCEPTIONS => e
|
72
|
+
if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
|
73
|
+
raise Faraday::SSLError, e
|
49
74
|
end
|
75
|
+
|
76
|
+
raise Faraday::ConnectionFailed, e
|
50
77
|
end
|
78
|
+
end
|
51
79
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
80
|
+
save_response(env, http_response.code.to_i,
|
81
|
+
http_response.body || +'', nil,
|
82
|
+
http_response.message) do |response_headers|
|
83
|
+
http_response.each_header do |key, value|
|
84
|
+
response_headers[key] = value
|
56
85
|
end
|
57
86
|
end
|
58
87
|
|
59
88
|
@app.call env
|
60
|
-
rescue Timeout::Error, Errno::ETIMEDOUT =>
|
61
|
-
raise Faraday::TimeoutError,
|
89
|
+
rescue Timeout::Error, Errno::ETIMEDOUT => e
|
90
|
+
raise Faraday::TimeoutError, e
|
62
91
|
end
|
63
92
|
|
64
93
|
private
|
65
94
|
|
66
95
|
def create_request(env)
|
67
96
|
request = Net::HTTPGenericRequest.new \
|
68
|
-
env[:method].to_s.upcase,
|
69
|
-
!!env[:body],
|
70
|
-
:
|
71
|
-
env[:url].request_uri,
|
72
|
-
env[:request_headers]
|
97
|
+
env[:method].to_s.upcase, # request method
|
98
|
+
!!env[:body], # is there request body
|
99
|
+
env[:method] != :head, # is there response body
|
100
|
+
env[:url].request_uri, # request uri path
|
101
|
+
env[:request_headers] # request headers
|
73
102
|
|
74
103
|
if env[:body].respond_to?(:read)
|
75
104
|
request.body_stream = env[:body]
|
@@ -80,62 +109,100 @@ module Faraday
|
|
80
109
|
end
|
81
110
|
|
82
111
|
def perform_request(http, env)
|
83
|
-
if
|
112
|
+
if env[:request].stream_response?
|
113
|
+
size = 0
|
114
|
+
yielded = false
|
115
|
+
http_response = request_with_wrapped_block(http, env) do |chunk|
|
116
|
+
if chunk.bytesize.positive? || size.positive?
|
117
|
+
yielded = true
|
118
|
+
size += chunk.bytesize
|
119
|
+
env[:request].on_data.call(chunk, size)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
env[:request].on_data.call(+'', 0) unless yielded
|
123
|
+
# Net::HTTP returns something,
|
124
|
+
# but it's not meaningful according to the docs.
|
125
|
+
http_response.body = nil
|
126
|
+
http_response
|
127
|
+
else
|
128
|
+
request_with_wrapped_block(http, env)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def request_with_wrapped_block(http, env, &block)
|
133
|
+
if (env[:method] == :get) && !env[:body]
|
84
134
|
# prefer `get` to `request` because the former handles gzip (ruby 1.9)
|
85
|
-
http
|
135
|
+
request_via_get_method(http, env, &block)
|
86
136
|
else
|
87
|
-
http
|
137
|
+
request_via_request_method(http, env, &block)
|
88
138
|
end
|
89
139
|
end
|
90
140
|
|
91
|
-
def
|
92
|
-
|
141
|
+
def request_via_get_method(http, env, &block)
|
142
|
+
# Must use Net::HTTP#start and pass it a block otherwise the server's
|
143
|
+
# TCP socket does not close correctly.
|
144
|
+
http.start do |opened_http|
|
145
|
+
opened_http.get env[:url].request_uri, env[:request_headers], &block
|
146
|
+
end
|
93
147
|
end
|
94
148
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
149
|
+
def request_via_request_method(http, env, &block)
|
150
|
+
# Must use Net::HTTP#start and pass it a block otherwise the server's
|
151
|
+
# TCP socket does not close correctly.
|
152
|
+
http.start do |opened_http|
|
153
|
+
if block_given?
|
154
|
+
opened_http.request create_request(env) do |response|
|
155
|
+
response.read_body(&block)
|
156
|
+
end
|
157
|
+
else
|
158
|
+
opened_http.request create_request(env)
|
159
|
+
end
|
160
|
+
end
|
101
161
|
end
|
102
162
|
|
103
163
|
def configure_ssl(http, ssl)
|
104
|
-
|
105
|
-
|
106
|
-
http.
|
107
|
-
|
108
|
-
|
109
|
-
http.
|
110
|
-
http.
|
111
|
-
http.
|
164
|
+
return unless ssl
|
165
|
+
|
166
|
+
http.verify_mode = ssl_verify_mode(ssl)
|
167
|
+
http.cert_store = ssl_cert_store(ssl)
|
168
|
+
|
169
|
+
http.cert = ssl[:client_cert] if ssl[:client_cert]
|
170
|
+
http.key = ssl[:client_key] if ssl[:client_key]
|
171
|
+
http.ca_file = ssl[:ca_file] if ssl[:ca_file]
|
172
|
+
http.ca_path = ssl[:ca_path] if ssl[:ca_path]
|
112
173
|
http.verify_depth = ssl[:verify_depth] if ssl[:verify_depth]
|
113
|
-
http.ssl_version
|
114
|
-
http.min_version
|
115
|
-
http.max_version
|
174
|
+
http.ssl_version = ssl[:version] if ssl[:version]
|
175
|
+
http.min_version = ssl[:min_version] if ssl[:min_version]
|
176
|
+
http.max_version = ssl[:max_version] if ssl[:max_version]
|
116
177
|
end
|
117
178
|
|
118
179
|
def configure_request(http, req)
|
119
|
-
if req
|
120
|
-
http.read_timeout
|
121
|
-
http.open_timeout = req[:timeout]
|
122
|
-
http.write_timeout = req[:timeout] if http.respond_to?(:write_timeout=)
|
180
|
+
if (sec = request_timeout(:read, req))
|
181
|
+
http.read_timeout = sec
|
123
182
|
end
|
124
|
-
http.open_timeout = req[:open_timeout] if req[:open_timeout]
|
125
|
-
http.write_timeout = req[:write_timeout] if req[:write_timeout] && http.respond_to?(:write_timeout=)
|
126
|
-
# Only set if Net::Http supports it, since Ruby 2.5.
|
127
|
-
http.max_retries = 0 if http.respond_to?(:max_retries=)
|
128
183
|
|
129
|
-
|
184
|
+
if (sec = http.respond_to?(:write_timeout=) &&
|
185
|
+
request_timeout(:write, req))
|
186
|
+
http.write_timeout = sec
|
187
|
+
end
|
188
|
+
|
189
|
+
if (sec = request_timeout(:open, req))
|
190
|
+
http.open_timeout = sec
|
191
|
+
end
|
192
|
+
|
193
|
+
# Only set if Net::Http supports it, since Ruby 2.5.
|
194
|
+
http.max_retries = 0 if http.respond_to?(:max_retries=)
|
195
|
+
|
196
|
+
@config_block&.call(http)
|
130
197
|
end
|
131
198
|
|
132
199
|
def ssl_cert_store(ssl)
|
133
200
|
return ssl[:cert_store] if ssl[:cert_store]
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
201
|
+
|
202
|
+
@ssl_cert_store ||= begin
|
203
|
+
# Use the default cert store by default, i.e. system ca certs
|
204
|
+
OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
205
|
+
end
|
139
206
|
end
|
140
207
|
|
141
208
|
def ssl_verify_mode(ssl)
|