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,43 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'openssl'
|
2
4
|
require 'em-http'
|
3
5
|
|
6
|
+
# EventMachine patch to make SSL work.
|
4
7
|
module EmHttpSslPatch
|
5
8
|
def ssl_verify_peer(cert_string)
|
6
|
-
cert = nil
|
7
9
|
begin
|
8
|
-
|
10
|
+
@last_seen_cert = OpenSSL::X509::Certificate.new(cert_string)
|
9
11
|
rescue OpenSSL::X509::CertificateError
|
10
12
|
return false
|
11
13
|
end
|
12
14
|
|
13
|
-
@last_seen_cert
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
raise OpenSSL::SSL::SSLError.new(%(unable to verify the server certificate for "#{host}"))
|
15
|
+
unless certificate_store.verify(@last_seen_cert)
|
16
|
+
raise OpenSSL::SSL::SSLError,
|
17
|
+
%(unable to verify the server certificate for "#{host}")
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
certificate_store.add_cert(@last_seen_cert)
|
22
|
+
rescue OpenSSL::X509::StoreError => e
|
23
|
+
raise e unless e.message == 'cert already in hash table'
|
24
24
|
end
|
25
|
+
true
|
25
26
|
end
|
26
27
|
|
27
28
|
def ssl_handshake_completed
|
28
29
|
return true unless verify_peer?
|
29
30
|
|
30
|
-
unless
|
31
|
-
raise OpenSSL::SSL::SSLError
|
32
|
-
|
33
|
-
true
|
31
|
+
unless verified_cert_identity?
|
32
|
+
raise OpenSSL::SSL::SSLError,
|
33
|
+
%(host "#{host}" does not match the server certificate)
|
34
34
|
end
|
35
|
+
|
36
|
+
true
|
35
37
|
end
|
36
38
|
|
37
39
|
def verify_peer?
|
38
40
|
parent.connopts.tls[:verify_peer]
|
39
41
|
end
|
40
42
|
|
43
|
+
def verified_cert_identity?
|
44
|
+
OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
|
45
|
+
end
|
46
|
+
|
41
47
|
def host
|
42
48
|
parent.uri.host
|
43
49
|
end
|
@@ -53,4 +59,4 @@ module EmHttpSslPatch
|
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
56
|
-
EventMachine::HttpStubConnection.
|
62
|
+
EventMachine::HttpStubConnection.include(EmHttpSslPatch)
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module Faraday
|
4
6
|
class Adapter
|
7
|
+
# EventMachine Synchrony adapter.
|
5
8
|
class EMSynchrony < Faraday::Adapter
|
6
9
|
include EMHttp::Options
|
7
10
|
|
@@ -13,7 +16,8 @@ module Faraday
|
|
13
16
|
|
14
17
|
self.supports_parallel = true
|
15
18
|
|
16
|
-
|
19
|
+
# @return [ParallelManager]
|
20
|
+
def self.setup_parallel_manager(_options = nil)
|
17
21
|
ParallelManager.new
|
18
22
|
end
|
19
23
|
|
@@ -23,73 +27,110 @@ module Faraday
|
|
23
27
|
|
24
28
|
http_method = env[:method].to_s.downcase.to_sym
|
25
29
|
|
26
|
-
# Queue requests for parallel execution.
|
27
30
|
if env[:parallel_manager]
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# Queue requests for parallel execution.
|
32
|
+
execute_parallel_request(env, request, http_method)
|
33
|
+
else
|
34
|
+
# Execute single request.
|
35
|
+
execute_single_request(env, request, http_method)
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
@app.call env
|
39
|
+
rescue Errno::ECONNREFUSED
|
40
|
+
raise Faraday::ConnectionFailed, $ERROR_INFO
|
41
|
+
rescue EventMachine::Connectify::CONNECTError => e
|
42
|
+
if e.message.include?('Proxy Authentication Required')
|
43
|
+
raise Faraday::ConnectionFailed,
|
44
|
+
%(407 "Proxy Authentication Required")
|
45
|
+
end
|
38
46
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
raise Faraday::ConnectionFailed, e
|
48
|
+
rescue Errno::ETIMEDOUT => e
|
49
|
+
raise Faraday::TimeoutError, e
|
50
|
+
rescue RuntimeError => e
|
51
|
+
if e.message == 'connection closed by server'
|
52
|
+
raise Faraday::ConnectionFailed, e
|
53
|
+
end
|
54
|
+
|
55
|
+
raise Faraday::TimeoutError, e if e.message.include?('timeout error')
|
56
|
+
|
57
|
+
raise
|
58
|
+
rescue StandardError => e
|
59
|
+
if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
|
60
|
+
raise Faraday::SSLError, e
|
61
|
+
end
|
62
|
+
|
63
|
+
raise
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_request(env)
|
67
|
+
EventMachine::HttpRequest.new(
|
68
|
+
Utils::URI(env[:url].to_s),
|
69
|
+
connection_config(env).merge(@connection_options)
|
70
|
+
)
|
71
|
+
end
|
54
72
|
|
55
|
-
|
73
|
+
private
|
56
74
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
75
|
+
def execute_parallel_request(env, request, http_method)
|
76
|
+
env[:parallel_manager].add(request, http_method,
|
77
|
+
request_config(env)) do |resp|
|
78
|
+
if (req = env[:request]).stream_response?
|
79
|
+
warn "Streaming downloads for #{self.class.name} " \
|
80
|
+
'are not yet implemented.'
|
81
|
+
req.on_data.call(resp.response, resp.response.bytesize)
|
82
|
+
end
|
83
|
+
|
84
|
+
save_response(env, resp.response_header.status,
|
85
|
+
resp.response) do |resp_headers|
|
86
|
+
resp.response_header.each do |name, value|
|
61
87
|
resp_headers[name.to_sym] = value
|
62
88
|
end
|
63
89
|
end
|
90
|
+
|
91
|
+
# Finalize the response object with values from `env`.
|
92
|
+
env[:response].finish(env)
|
64
93
|
end
|
94
|
+
end
|
65
95
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
96
|
+
def execute_single_request(env, request, http_method)
|
97
|
+
block = -> { request.send(http_method, request_config(env)) }
|
98
|
+
client = call_block(block)
|
99
|
+
|
100
|
+
raise client.error if client&.error
|
101
|
+
|
102
|
+
if env[:request].stream_response?
|
103
|
+
warn "Streaming downloads for #{self.class.name} " \
|
104
|
+
'are not yet implemented.'
|
105
|
+
env[:request].on_data.call(
|
106
|
+
client.response,
|
107
|
+
client.response.bytesize
|
108
|
+
)
|
74
109
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
raise
|
110
|
+
status = client.response_header.status
|
111
|
+
reason = client.response_header.http_reason
|
112
|
+
save_response(env, status, client.response, nil, reason) do |headers|
|
113
|
+
client.response_header.each do |name, value|
|
114
|
+
headers[name.to_sym] = value
|
115
|
+
end
|
82
116
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
117
|
+
end
|
118
|
+
|
119
|
+
def call_block(block)
|
120
|
+
client = nil
|
121
|
+
|
122
|
+
if EM.reactor_running?
|
123
|
+
client = block.call
|
86
124
|
else
|
87
|
-
|
125
|
+
EM.run do
|
126
|
+
Fiber.new do
|
127
|
+
client = block.call
|
128
|
+
EM.stop
|
129
|
+
end.resume
|
130
|
+
end
|
88
131
|
end
|
89
|
-
end
|
90
132
|
|
91
|
-
|
92
|
-
EventMachine::HttpRequest.new(Utils::URI(env[:url].to_s), connection_config(env).merge(@connection_options))
|
133
|
+
client
|
93
134
|
end
|
94
135
|
end
|
95
136
|
end
|
@@ -97,10 +138,13 @@ end
|
|
97
138
|
|
98
139
|
require 'faraday/adapter/em_synchrony/parallel_manager'
|
99
140
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
141
|
+
if Faraday::Adapter::EMSynchrony.loaded?
|
142
|
+
begin
|
143
|
+
require 'openssl'
|
144
|
+
rescue LoadError
|
145
|
+
warn 'Warning: no such file to load -- openssl. ' \
|
146
|
+
'Make sure it is installed if you want HTTPS support'
|
147
|
+
else
|
148
|
+
require 'faraday/adapter/em_http_ssl_patch'
|
149
|
+
end
|
150
|
+
end
|
@@ -1,16 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Faraday
|
2
4
|
class Adapter
|
3
5
|
class EMSynchrony < Faraday::Adapter
|
6
|
+
# A parallel manager for EMSynchrony.
|
4
7
|
class ParallelManager
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
+
# Add requests to queue.
|
9
|
+
#
|
10
|
+
# @param request [EM::HttpRequest]
|
11
|
+
# @param method [Symbol, String] HTTP method
|
12
|
+
# @param args [Array] the rest of the positional arguments
|
8
13
|
def add(request, method, *args, &block)
|
9
14
|
queue << {
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
15
|
+
request: request,
|
16
|
+
method: method,
|
17
|
+
args: args,
|
18
|
+
block: block
|
14
19
|
}
|
15
20
|
end
|
16
21
|
|
@@ -19,19 +24,18 @@ module Faraday
|
|
19
24
|
def run
|
20
25
|
result = nil
|
21
26
|
if !EM.reactor_running?
|
22
|
-
EM.run
|
27
|
+
EM.run do
|
23
28
|
Fiber.new do
|
24
29
|
result = perform
|
25
30
|
EM.stop
|
26
31
|
end.resume
|
27
|
-
|
32
|
+
end
|
28
33
|
else
|
29
34
|
result = perform
|
30
35
|
end
|
31
36
|
result
|
32
37
|
end
|
33
38
|
|
34
|
-
|
35
39
|
private
|
36
40
|
|
37
41
|
# The request queue.
|
@@ -59,8 +63,7 @@ module Faraday
|
|
59
63
|
# Block fiber until all requests have returned.
|
60
64
|
multi.perform
|
61
65
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end # Faraday
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,81 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Faraday
|
2
4
|
class Adapter
|
5
|
+
# Excon adapter.
|
3
6
|
class Excon < Faraday::Adapter
|
4
7
|
dependency 'excon'
|
5
8
|
|
9
|
+
def build_connection(env)
|
10
|
+
opts = opts_from_env(env)
|
11
|
+
::Excon.new(env[:url].to_s, opts.merge(@connection_options))
|
12
|
+
end
|
13
|
+
|
6
14
|
def call(env)
|
7
15
|
super
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
opts[:client_cert] = ssl[:client_cert] if ssl[:client_cert]
|
15
|
-
opts[:client_key] = ssl[:client_key] if ssl[:client_key]
|
16
|
-
opts[:certificate] = ssl[:certificate] if ssl[:certificate]
|
17
|
-
opts[:private_key] = ssl[:private_key] if ssl[:private_key]
|
18
|
-
opts[:ssl_version] = ssl[:version] if ssl[:version]
|
19
|
-
opts[:ssl_min_version] = ssl[:min_version] if ssl[:min_version]
|
20
|
-
opts[:ssl_max_version] = ssl[:max_version] if ssl[:max_version]
|
21
|
-
|
22
|
-
# https://github.com/geemus/excon/issues/106
|
23
|
-
# https://github.com/jruby/jruby-ossl/issues/19
|
24
|
-
opts[:nonblock] = false
|
25
|
-
end
|
17
|
+
req_opts = {
|
18
|
+
method: env[:method].to_s.upcase,
|
19
|
+
headers: env[:request_headers],
|
20
|
+
body: read_body(env)
|
21
|
+
}
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
req = env[:request]
|
24
|
+
if req&.stream_response?
|
25
|
+
total = 0
|
26
|
+
req_opts[:response_block] = lambda do |chunk, _remain, _total|
|
27
|
+
req.on_data.call(chunk, total += chunk.size)
|
32
28
|
end
|
29
|
+
end
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
resp = connection(env) { |http| http.request(req_opts) }
|
32
|
+
save_response(env, resp.status.to_i, resp.body, resp.headers,
|
33
|
+
resp.reason_phrase)
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
35
|
+
@app.call(env)
|
36
|
+
rescue ::Excon::Errors::SocketError => e
|
37
|
+
raise Faraday::TimeoutError, e if e.message =~ /\btimeout\b/
|
38
|
+
|
39
|
+
raise Faraday::SSLError, e if e.message =~ /\bcertificate\b/
|
40
|
+
|
41
|
+
raise Faraday::ConnectionFailed, e
|
42
|
+
rescue ::Excon::Errors::Timeout => e
|
43
|
+
raise Faraday::TimeoutError, e
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: support streaming requests
|
47
|
+
def read_body(env)
|
48
|
+
env[:body].respond_to?(:read) ? env[:body].read : env[:body]
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def opts_from_env(env)
|
54
|
+
opts = {}
|
55
|
+
amend_opts_with_ssl!(opts, env[:ssl]) if needs_ssl_settings?(env)
|
56
|
+
|
57
|
+
if (req = env[:request])
|
58
|
+
amend_opts_with_timeouts!(opts, req)
|
59
|
+
amend_opts_with_proxy_settings!(opts, req)
|
48
60
|
end
|
49
61
|
|
50
|
-
|
62
|
+
opts
|
63
|
+
end
|
51
64
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
:body => read_body(env)
|
65
|
+
def needs_ssl_settings?(env)
|
66
|
+
env[:url].scheme == 'https' && env[:ssl]
|
67
|
+
end
|
56
68
|
|
57
|
-
|
69
|
+
OPTS_KEYS = [
|
70
|
+
%i[client_cert client_cert],
|
71
|
+
%i[client_key client_key],
|
72
|
+
%i[certificate certificate],
|
73
|
+
%i[private_key private_key],
|
74
|
+
%i[ssl_ca_path ca_path],
|
75
|
+
%i[ssl_ca_file ca_file],
|
76
|
+
%i[ssl_version version],
|
77
|
+
%i[ssl_min_version min_version],
|
78
|
+
%i[ssl_max_version max_version]
|
79
|
+
].freeze
|
58
80
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
81
|
+
def amend_opts_with_ssl!(opts, ssl)
|
82
|
+
opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
|
83
|
+
# https://github.com/geemus/excon/issues/106
|
84
|
+
# https://github.com/jruby/jruby-ossl/issues/19
|
85
|
+
opts[:nonblock] = false
|
86
|
+
|
87
|
+
OPTS_KEYS.each do |(key_in_opts, key_in_ssl)|
|
88
|
+
next unless ssl[key_in_ssl]
|
89
|
+
|
90
|
+
opts[key_in_opts] = ssl[key_in_ssl]
|
67
91
|
end
|
68
|
-
rescue ::Excon::Errors::Timeout => err
|
69
|
-
raise Faraday::TimeoutError, err
|
70
92
|
end
|
71
93
|
|
72
|
-
def
|
73
|
-
|
94
|
+
def amend_opts_with_timeouts!(opts, req)
|
95
|
+
if (sec = request_timeout(:read, req))
|
96
|
+
opts[:read_timeout] = sec
|
97
|
+
end
|
98
|
+
|
99
|
+
if (sec = request_timeout(:write, req))
|
100
|
+
opts[:write_timeout] = sec
|
101
|
+
end
|
102
|
+
|
103
|
+
return unless (sec = request_timeout(:open, req))
|
104
|
+
|
105
|
+
opts[:connect_timeout] = sec
|
74
106
|
end
|
75
107
|
|
76
|
-
|
77
|
-
|
78
|
-
|
108
|
+
def amend_opts_with_proxy_settings!(opts, req)
|
109
|
+
opts[:proxy] = proxy_settings_for_opts(req[:proxy]) if req[:proxy]
|
110
|
+
end
|
111
|
+
|
112
|
+
def proxy_settings_for_opts(proxy)
|
113
|
+
{
|
114
|
+
host: proxy[:uri].host,
|
115
|
+
hostname: proxy[:uri].hostname,
|
116
|
+
port: proxy[:uri].port,
|
117
|
+
scheme: proxy[:uri].scheme,
|
118
|
+
user: proxy[:user],
|
119
|
+
password: proxy[:password]
|
120
|
+
}
|
79
121
|
end
|
80
122
|
end
|
81
123
|
end
|