mirror of
https://github.com/lostisland/faraday.git
synced 2025-11-12 00:04:04 -05:00
fix EMHttp and Typhoeus request timeout implementations
This commit is contained in:
parent
2c1f8b1d7f
commit
97b24b9878
@ -34,11 +34,11 @@ module Faraday
|
|||||||
perform_single_request(env).
|
perform_single_request(env).
|
||||||
callback { EventMachine.stop }.
|
callback { EventMachine.stop }.
|
||||||
errback { |client|
|
errback { |client|
|
||||||
error = client.error || "connection failed"
|
error = error_message(client)
|
||||||
EventMachine.stop
|
EventMachine.stop
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
raise Faraday::Error::ClientError, error if error
|
raise_error(error) if error
|
||||||
else
|
else
|
||||||
# EM is running: instruct upstream that this is an async request
|
# EM is running: instruct upstream that this is an async request
|
||||||
env[:parallel_manager] = true
|
env[:parallel_manager] = true
|
||||||
@ -64,6 +64,19 @@ module Faraday
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_message(client)
|
||||||
|
client.error or "request failed"
|
||||||
|
end
|
||||||
|
|
||||||
|
def raise_error(msg)
|
||||||
|
errklass = Faraday::Error::ClientError
|
||||||
|
if msg == Errno::ETIMEDOUT
|
||||||
|
errklass = Faraday::Error::TimeoutError
|
||||||
|
msg = "request timed out"
|
||||||
|
end
|
||||||
|
raise errklass, msg
|
||||||
|
end
|
||||||
|
|
||||||
def connection_config(env)
|
def connection_config(env)
|
||||||
options = {}
|
options = {}
|
||||||
configure_ssl(options, env)
|
configure_ssl(options, env)
|
||||||
|
|||||||
@ -42,6 +42,14 @@ module Faraday
|
|||||||
configure_timeout req, env
|
configure_timeout req, env
|
||||||
|
|
||||||
req.on_complete do |resp|
|
req.on_complete do |resp|
|
||||||
|
if resp.timed_out?
|
||||||
|
if parallel?(env)
|
||||||
|
# TODO: error callback in async mode
|
||||||
|
else
|
||||||
|
raise Faraday::Error::TimeoutError, "request timed out"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
save_response(env, resp.code, resp.body) do |response_headers|
|
save_response(env, resp.code, resp.body) do |response_headers|
|
||||||
response_headers.parse resp.headers
|
response_headers.parse resp.headers
|
||||||
end
|
end
|
||||||
|
|||||||
@ -185,9 +185,10 @@ else
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if %w[Faraday::Adapter::Patron Faraday::Adapter::NetHttp].include?(adapter.to_s)
|
# https://github.com/eventmachine/eventmachine/pull/289
|
||||||
|
unless %w[Faraday::Adapter::EMHttp Faraday::Adapter::EMSynchrony Faraday::Adapter::Excon].include?(adapter.to_s)
|
||||||
define_method "test_#{adapter}_timeout" do
|
define_method "test_#{adapter}_timeout" do
|
||||||
conn = create_connection(adapter, :request => {:timeout => 1, :read_timeout => 1})
|
conn = create_connection(adapter, :request => {:timeout => 1, :open_timeout => 1})
|
||||||
assert_raise Faraday::Error::TimeoutError do
|
assert_raise Faraday::Error::TimeoutError do
|
||||||
conn.get '/slow'
|
conn.get '/slow'
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user