faraday 0.12.2 → 1.3.0
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 +5 -5
- data/CHANGELOG.md +350 -0
- data/LICENSE.md +1 -1
- data/README.md +22 -325
- data/Rakefile +7 -0
- data/examples/client_spec.rb +65 -0
- data/examples/client_test.rb +79 -0
- data/lib/faraday.rb +120 -188
- data/lib/faraday/adapter.rb +84 -22
- data/lib/faraday/adapter/em_http.rb +150 -104
- data/lib/faraday/adapter/em_http_ssl_patch.rb +24 -18
- data/lib/faraday/adapter/em_synchrony.rb +110 -63
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
- data/lib/faraday/adapter/excon.rb +98 -54
- data/lib/faraday/adapter/httpclient.rb +83 -59
- data/lib/faraday/adapter/net_http_persistent.rb +68 -27
- data/lib/faraday/adapter/patron.rb +86 -37
- data/lib/faraday/adapter/rack.rb +30 -13
- data/lib/faraday/adapter/test.rb +103 -62
- data/lib/faraday/adapter/typhoeus.rb +7 -115
- data/lib/faraday/adapter_registry.rb +30 -0
- data/lib/faraday/autoload.rb +46 -36
- data/lib/faraday/connection.rb +336 -177
- data/lib/faraday/dependency_loader.rb +37 -0
- data/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +176 -0
- data/lib/faraday/error.rb +126 -37
- data/lib/faraday/file_part.rb +128 -0
- data/lib/faraday/logging/formatter.rb +105 -0
- data/lib/faraday/methods.rb +6 -0
- data/lib/faraday/middleware.rb +19 -25
- data/lib/faraday/middleware_registry.rb +129 -0
- data/lib/faraday/options.rb +39 -193
- 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 -196
- data/lib/faraday/rack_builder.rb +77 -63
- data/lib/faraday/request.rb +94 -32
- 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 +86 -48
- data/lib/faraday/request/retry.rb +209 -134
- data/lib/faraday/request/token_authentication.rb +15 -10
- data/lib/faraday/request/url_encoded.rb +43 -23
- data/lib/faraday/response.rb +27 -23
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +49 -14
- data/lib/faraday/utils.rb +38 -247
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/lib/faraday/version.rb +5 -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/test_spec.rb +260 -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 +60 -0
- data/spec/faraday/middleware_spec.rb +52 -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 +42 -0
- data/spec/faraday/params_encoders/nested_spec.rb +142 -0
- data/spec/faraday/rack_builder_spec.rb +345 -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 +302 -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 +120 -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 +169 -0
- 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 +132 -0
- 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 +105 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +262 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- data/spec/support/webmock_rack_app.rb +68 -0
- metadata +109 -10
- data/lib/faraday/adapter/net_http.rb +0 -135
- data/lib/faraday/upload_io.rb +0 -67
data/lib/faraday/adapter.rb
CHANGED
@@ -1,53 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Faraday
|
2
|
-
#
|
4
|
+
# Base class for all Faraday adapters. Adapters are
|
3
5
|
# responsible for fulfilling a Faraday request.
|
4
|
-
class Adapter
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
class Adapter
|
7
|
+
extend MiddlewareRegistry
|
8
|
+
extend DependencyLoader
|
9
|
+
|
10
|
+
CONTENT_LENGTH = 'Content-Length'
|
11
|
+
|
12
|
+
register_middleware File.expand_path('adapter', __dir__),
|
13
|
+
test: [:Test, 'test'],
|
14
|
+
net_http_persistent: [
|
15
|
+
:NetHttpPersistent,
|
16
|
+
'net_http_persistent'
|
17
|
+
],
|
18
|
+
typhoeus: [:Typhoeus, 'typhoeus'],
|
19
|
+
patron: [:Patron, 'patron'],
|
20
|
+
em_synchrony: [:EMSynchrony, 'em_synchrony'],
|
21
|
+
em_http: [:EMHttp, 'em_http'],
|
22
|
+
excon: [:Excon, 'excon'],
|
23
|
+
rack: [:Rack, 'rack'],
|
24
|
+
httpclient: [:HTTPClient, 'httpclient']
|
25
|
+
|
26
|
+
# This module marks an Adapter as supporting parallel requests.
|
20
27
|
module Parallelism
|
21
28
|
attr_writer :supports_parallel
|
22
|
-
|
29
|
+
|
30
|
+
def supports_parallel?
|
31
|
+
@supports_parallel
|
32
|
+
end
|
23
33
|
|
24
34
|
def inherited(subclass)
|
25
35
|
super
|
26
|
-
subclass.supports_parallel =
|
36
|
+
subclass.supports_parallel = supports_parallel?
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
40
|
extend Parallelism
|
31
41
|
self.supports_parallel = false
|
32
42
|
|
33
|
-
def initialize(
|
34
|
-
|
43
|
+
def initialize(_app = nil, opts = {}, &block)
|
44
|
+
@app = ->(env) { env.response }
|
35
45
|
@connection_options = opts
|
36
46
|
@config_block = block
|
37
47
|
end
|
38
48
|
|
49
|
+
# Yields or returns an adapter's configured connection. Depends on
|
50
|
+
# #build_connection being defined on this adapter.
|
51
|
+
#
|
52
|
+
# @param env [Faraday::Env, Hash] The env object for a faraday request.
|
53
|
+
#
|
54
|
+
# @return The return value of the given block, or the HTTP connection object
|
55
|
+
# if no block is given.
|
56
|
+
def connection(env)
|
57
|
+
conn = build_connection(env)
|
58
|
+
return conn unless block_given?
|
59
|
+
|
60
|
+
yield conn
|
61
|
+
end
|
62
|
+
|
63
|
+
# Close any persistent connections. The adapter should still be usable
|
64
|
+
# after calling close.
|
65
|
+
def close
|
66
|
+
# Possible implementation:
|
67
|
+
# @app.close if @app.respond_to?(:close)
|
68
|
+
end
|
69
|
+
|
39
70
|
def call(env)
|
40
71
|
env.clear_body if env.needs_body?
|
72
|
+
env.response = Response.new
|
41
73
|
end
|
42
74
|
|
75
|
+
private
|
76
|
+
|
43
77
|
def save_response(env, status, body, headers = nil, reason_phrase = nil)
|
44
78
|
env.status = status
|
45
79
|
env.body = body
|
46
|
-
env.reason_phrase = reason_phrase
|
80
|
+
env.reason_phrase = reason_phrase&.to_s&.strip
|
47
81
|
env.response_headers = Utils::Headers.new.tap do |response_headers|
|
48
82
|
response_headers.update headers unless headers.nil?
|
49
83
|
yield(response_headers) if block_given?
|
50
84
|
end
|
85
|
+
|
86
|
+
env.response.finish(env) unless env.parallel?
|
87
|
+
env.response
|
88
|
+
end
|
89
|
+
|
90
|
+
# Fetches either a read, write, or open timeout setting. Defaults to the
|
91
|
+
# :timeout value if a more specific one is not given.
|
92
|
+
#
|
93
|
+
# @param type [Symbol] Describes which timeout setting to get: :read,
|
94
|
+
# :write, or :open.
|
95
|
+
# @param options [Hash] Hash containing Symbol keys like :timeout,
|
96
|
+
# :read_timeout, :write_timeout, :open_timeout, or
|
97
|
+
# :timeout
|
98
|
+
#
|
99
|
+
# @return [Integer, nil] Timeout duration in seconds, or nil if no timeout
|
100
|
+
# has been set.
|
101
|
+
def request_timeout(type, options)
|
102
|
+
key = TIMEOUT_KEYS.fetch(type) do
|
103
|
+
msg = "Expected :read, :write, :open. Got #{type.inspect} :("
|
104
|
+
raise ArgumentError, msg
|
105
|
+
end
|
106
|
+
options[key] || options[:timeout]
|
51
107
|
end
|
108
|
+
|
109
|
+
TIMEOUT_KEYS = {
|
110
|
+
read: :read_timeout,
|
111
|
+
open: :open_timeout,
|
112
|
+
write: :write_timeout
|
113
|
+
}.freeze
|
52
114
|
end
|
53
115
|
end
|
@@ -1,10 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Faraday
|
2
4
|
class Adapter
|
3
|
-
# EventMachine adapter is useful for either asynchronous
|
4
|
-
# when in EM reactor loop or for making parallel requests in
|
5
|
+
# EventMachine adapter. This adapter is useful for either asynchronous
|
6
|
+
# requests when in an EM reactor loop, or for making parallel requests in
|
5
7
|
# synchronous code.
|
6
8
|
class EMHttp < Faraday::Adapter
|
9
|
+
# Options is a module containing helpers to convert the Faraday env object
|
10
|
+
# into options hashes for EMHTTP method calls.
|
7
11
|
module Options
|
12
|
+
# @return [Hash]
|
8
13
|
def connection_config(env)
|
9
14
|
options = {}
|
10
15
|
configure_proxy(options, env)
|
@@ -16,10 +21,10 @@ module Faraday
|
|
16
21
|
|
17
22
|
def request_config(env)
|
18
23
|
options = {
|
19
|
-
:
|
20
|
-
:
|
21
|
-
# :
|
22
|
-
# :
|
24
|
+
body: read_body(env),
|
25
|
+
head: env[:request_headers]
|
26
|
+
# keepalive: true,
|
27
|
+
# file: 'path/to/file', # stream data off disk
|
23
28
|
}
|
24
29
|
configure_compression(options, env)
|
25
30
|
options
|
@@ -30,44 +35,52 @@ module Faraday
|
|
30
35
|
body.respond_to?(:read) ? body.read : body
|
31
36
|
end
|
32
37
|
|
38
|
+
# Reads out proxy settings from env into options
|
33
39
|
def configure_proxy(options, env)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
proxy = request_options(env)[:proxy]
|
41
|
+
return unless proxy
|
42
|
+
|
43
|
+
options[:proxy] = {
|
44
|
+
host: proxy[:uri].host,
|
45
|
+
port: proxy[:uri].port,
|
46
|
+
authorization: [proxy[:user], proxy[:password]]
|
47
|
+
}
|
41
48
|
end
|
42
49
|
|
50
|
+
# Reads out host and port settings from env into options
|
43
51
|
def configure_socket(options, env)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
52
|
+
bind = request_options(env)[:bind]
|
53
|
+
return unless bind
|
54
|
+
|
55
|
+
options[:bind] = {
|
56
|
+
host: bind[:host],
|
57
|
+
port: bind[:port]
|
58
|
+
}
|
50
59
|
end
|
51
60
|
|
61
|
+
# Reads out SSL certificate settings from env into options
|
52
62
|
def configure_ssl(options, env)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
63
|
+
return unless env[:url].scheme == 'https' && env[:ssl]
|
64
|
+
|
65
|
+
options[:ssl] = {
|
66
|
+
cert_chain_file: env[:ssl][:ca_file],
|
67
|
+
verify_peer: env[:ssl].fetch(:verify, true)
|
68
|
+
}
|
59
69
|
end
|
60
70
|
|
71
|
+
# Reads out timeout settings from env into options
|
61
72
|
def configure_timeout(options, env)
|
62
|
-
|
63
|
-
options[:
|
64
|
-
options[:connect_timeout] =
|
73
|
+
req = request_options(env)
|
74
|
+
options[:inactivity_timeout] = request_timeout(:read, req)
|
75
|
+
options[:connect_timeout] = request_timeout(:open, req)
|
65
76
|
end
|
66
77
|
|
78
|
+
# Reads out compression header settings from env into options
|
67
79
|
def configure_compression(options, env)
|
68
|
-
|
69
|
-
|
70
|
-
|
80
|
+
return unless (env[:method] == :get) &&
|
81
|
+
!options[:head].key?('accept-encoding')
|
82
|
+
|
83
|
+
options[:head]['accept-encoding'] = 'gzip, compressed'
|
71
84
|
end
|
72
85
|
|
73
86
|
def request_options(env)
|
@@ -77,11 +90,26 @@ module Faraday
|
|
77
90
|
|
78
91
|
include Options
|
79
92
|
|
80
|
-
dependency
|
93
|
+
dependency do
|
94
|
+
require 'em-http'
|
95
|
+
|
96
|
+
begin
|
97
|
+
require 'openssl'
|
98
|
+
rescue LoadError
|
99
|
+
warn 'Warning: no such file to load -- openssl. ' \
|
100
|
+
'Make sure it is installed if you want HTTPS support'
|
101
|
+
else
|
102
|
+
require 'em-http/version'
|
103
|
+
if EventMachine::HttpRequest::VERSION < '1.1.6'
|
104
|
+
require 'faraday/adapter/em_http_ssl_patch'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
81
108
|
|
82
109
|
self.supports_parallel = true
|
83
110
|
|
84
|
-
|
111
|
+
# @return [Manager]
|
112
|
+
def self.setup_parallel_manager(_options = nil)
|
85
113
|
Manager.new
|
86
114
|
end
|
87
115
|
|
@@ -94,95 +122,114 @@ module Faraday
|
|
94
122
|
def perform_request(env)
|
95
123
|
if parallel?(env)
|
96
124
|
manager = env[:parallel_manager]
|
97
|
-
manager.add
|
98
|
-
perform_single_request(env)
|
99
|
-
callback { env[:response].finish(env) }
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
error = error_message(client)
|
110
|
-
EventMachine.stop
|
111
|
-
}
|
125
|
+
manager.add do
|
126
|
+
perform_single_request(env)
|
127
|
+
.callback { env[:response].finish(env) }
|
128
|
+
end
|
129
|
+
elsif EventMachine.reactor_running?
|
130
|
+
# EM is running: instruct upstream that this is an async request
|
131
|
+
env[:parallel_manager] = true
|
132
|
+
perform_single_request(env)
|
133
|
+
.callback { env[:response].finish(env) }
|
134
|
+
.errback do
|
135
|
+
# TODO: no way to communicate the error in async mode
|
136
|
+
raise NotImplementedError
|
112
137
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
perform_single_request(env)
|
118
|
-
callback {
|
119
|
-
errback
|
120
|
-
|
121
|
-
|
122
|
-
|
138
|
+
else
|
139
|
+
error = nil
|
140
|
+
# start EM, block until request is completed
|
141
|
+
EventMachine.run do
|
142
|
+
perform_single_request(env)
|
143
|
+
.callback { EventMachine.stop }
|
144
|
+
.errback do |client|
|
145
|
+
error = error_message(client)
|
146
|
+
EventMachine.stop
|
147
|
+
end
|
123
148
|
end
|
149
|
+
raise_error(error) if error
|
124
150
|
end
|
125
|
-
rescue EventMachine::Connectify::CONNECTError =>
|
126
|
-
if
|
127
|
-
raise
|
128
|
-
|
129
|
-
raise Error::ConnectionFailed, err
|
151
|
+
rescue EventMachine::Connectify::CONNECTError => e
|
152
|
+
if e.message.include?('Proxy Authentication Required')
|
153
|
+
raise Faraday::ConnectionFailed,
|
154
|
+
%(407 "Proxy Authentication Required ")
|
130
155
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
156
|
+
|
157
|
+
raise Faraday::ConnectionFailed, e
|
158
|
+
rescue StandardError => e
|
159
|
+
if defined?(::OpenSSL::SSL::SSLError) && \
|
160
|
+
e.is_a?(::OpenSSL::SSL::SSLError)
|
161
|
+
raise Faraday::SSLError, e
|
136
162
|
end
|
163
|
+
|
164
|
+
raise
|
137
165
|
end
|
138
166
|
|
139
167
|
# TODO: reuse the connection to support pipelining
|
140
168
|
def perform_single_request(env)
|
141
169
|
req = create_request(env)
|
142
|
-
req.setup_request(env[:method], request_config(env))
|
170
|
+
req = req.setup_request(env[:method], request_config(env))
|
171
|
+
req.callback do |client|
|
172
|
+
if env[:request].stream_response?
|
173
|
+
warn "Streaming downloads for #{self.class.name} " \
|
174
|
+
'are not yet implemented.'
|
175
|
+
env[:request].on_data.call(
|
176
|
+
client.response,
|
177
|
+
client.response.bytesize
|
178
|
+
)
|
179
|
+
end
|
143
180
|
status = client.response_header.status
|
144
181
|
reason = client.response_header.http_reason
|
145
|
-
save_response(env, status, client.response, nil, reason) do |
|
182
|
+
save_response(env, status, client.response, nil, reason) do |headers|
|
146
183
|
client.response_header.each do |name, value|
|
147
|
-
|
184
|
+
headers[name.to_sym] = value
|
148
185
|
end
|
149
186
|
end
|
150
|
-
|
187
|
+
end
|
151
188
|
end
|
152
189
|
|
153
190
|
def create_request(env)
|
154
|
-
EventMachine::HttpRequest.new(
|
191
|
+
EventMachine::HttpRequest.new(
|
192
|
+
env[:url], connection_config(env).merge(@connection_options)
|
193
|
+
)
|
155
194
|
end
|
156
195
|
|
157
196
|
def error_message(client)
|
158
|
-
client.error
|
197
|
+
client.error || 'request failed'
|
159
198
|
end
|
160
199
|
|
161
200
|
def raise_error(msg)
|
162
|
-
|
163
|
-
if msg
|
164
|
-
|
165
|
-
msg =
|
201
|
+
error_class = Faraday::ClientError
|
202
|
+
if timeout_message?(msg)
|
203
|
+
error_class = Faraday::TimeoutError
|
204
|
+
msg = 'request timed out'
|
166
205
|
elsif msg == Errno::ECONNREFUSED
|
167
|
-
|
168
|
-
msg =
|
169
|
-
elsif msg ==
|
170
|
-
|
206
|
+
error_class = Faraday::ConnectionFailed
|
207
|
+
msg = 'connection refused'
|
208
|
+
elsif msg == 'connection closed by server'
|
209
|
+
error_class = Faraday::ConnectionFailed
|
171
210
|
end
|
172
|
-
raise
|
211
|
+
raise error_class, msg
|
173
212
|
end
|
174
213
|
|
214
|
+
def timeout_message?(msg)
|
215
|
+
msg == Errno::ETIMEDOUT ||
|
216
|
+
(msg.is_a?(String) && msg.include?('timeout error'))
|
217
|
+
end
|
218
|
+
|
219
|
+
# @return [Boolean]
|
175
220
|
def parallel?(env)
|
176
221
|
!!env[:parallel_manager]
|
177
222
|
end
|
178
223
|
|
179
|
-
#
|
224
|
+
# This parallel manager is designed to start an EventMachine loop
|
180
225
|
# and block until all registered requests have been completed.
|
181
226
|
class Manager
|
227
|
+
# @see reset
|
182
228
|
def initialize
|
183
229
|
reset
|
184
230
|
end
|
185
231
|
|
232
|
+
# Re-initializes instance variables
|
186
233
|
def reset
|
187
234
|
@registered_procs = []
|
188
235
|
@num_registered = 0
|
@@ -191,27 +238,30 @@ module Faraday
|
|
191
238
|
@running = false
|
192
239
|
end
|
193
240
|
|
194
|
-
|
241
|
+
# @return [Boolean]
|
242
|
+
def running?
|
243
|
+
@running
|
244
|
+
end
|
195
245
|
|
196
|
-
def add
|
246
|
+
def add(&block)
|
197
247
|
if running?
|
198
|
-
perform_request
|
248
|
+
perform_request(&block)
|
199
249
|
else
|
200
|
-
@registered_procs <<
|
250
|
+
@registered_procs << block
|
201
251
|
end
|
202
252
|
@num_registered += 1
|
203
253
|
end
|
204
254
|
|
205
255
|
def run
|
206
|
-
if @num_registered
|
256
|
+
if @num_registered.positive?
|
207
257
|
@running = true
|
208
258
|
EventMachine.run do
|
209
259
|
@registered_procs.each do |proc|
|
210
260
|
perform_request(&proc)
|
211
261
|
end
|
212
262
|
end
|
213
|
-
|
214
|
-
raise Faraday::
|
263
|
+
unless @errors.empty?
|
264
|
+
raise Faraday::ClientError, @errors.first || 'connection failed'
|
215
265
|
end
|
216
266
|
end
|
217
267
|
ensure
|
@@ -220,24 +270,20 @@ module Faraday
|
|
220
270
|
|
221
271
|
def perform_request
|
222
272
|
client = yield
|
223
|
-
client.callback
|
224
|
-
|
273
|
+
client.callback do
|
274
|
+
@num_succeeded += 1
|
275
|
+
check_finished
|
276
|
+
end
|
277
|
+
client.errback do
|
278
|
+
@errors << client.error
|
279
|
+
check_finished
|
280
|
+
end
|
225
281
|
end
|
226
282
|
|
227
283
|
def check_finished
|
228
|
-
if @num_succeeded + @errors.size == @num_registered
|
229
|
-
EventMachine.stop
|
230
|
-
end
|
284
|
+
EventMachine.stop if @num_succeeded + @errors.size == @num_registered
|
231
285
|
end
|
232
286
|
end
|
233
287
|
end
|
234
288
|
end
|
235
289
|
end
|
236
|
-
|
237
|
-
begin
|
238
|
-
require 'openssl'
|
239
|
-
rescue LoadError
|
240
|
-
warn "Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support"
|
241
|
-
else
|
242
|
-
require 'faraday/adapter/em_http_ssl_patch'
|
243
|
-
end if Faraday::Adapter::EMHttp.loaded?
|