mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-28 00:02:22 -05:00
updating faraday support for 0.16 version
This commit is contained in:
parent
be39f6b901
commit
237c3863f5
@ -6,6 +6,18 @@ require "faraday"
|
||||
module Faraday
|
||||
class Adapter
|
||||
class HTTPX < Faraday::Adapter
|
||||
SSL_ERROR = if defined?(Faraday::SSLError)
|
||||
Faraday::SSLError
|
||||
else
|
||||
Faraday::Error::SSLError
|
||||
end
|
||||
|
||||
CONNECTION_FAILED_ERROR = if defined?(Faraday::ConnectionFailed)
|
||||
Faraday::ConnectionFailed
|
||||
else
|
||||
Faraday::Error::ConnectionFailed
|
||||
end
|
||||
|
||||
module RequestMixin
|
||||
private
|
||||
|
||||
@ -162,6 +174,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def call(env)
|
||||
super
|
||||
if parallel?(env)
|
||||
handler = env[:parallel_manager].enqueue(env)
|
||||
handler.on_response do |response|
|
||||
@ -183,7 +196,7 @@ module Faraday
|
||||
end
|
||||
@app.call(env)
|
||||
rescue OpenSSL::SSL::SSLError => err
|
||||
raise Error::SSLError, err
|
||||
raise SSL_ERROR, err
|
||||
rescue Errno::ECONNABORTED,
|
||||
Errno::ECONNREFUSED,
|
||||
Errno::ECONNRESET,
|
||||
@ -191,7 +204,7 @@ module Faraday
|
||||
Errno::EINVAL,
|
||||
Errno::ENETUNREACH,
|
||||
Errno::EPIPE => err
|
||||
raise Error::ConnectionFailed, err
|
||||
raise CONNECTION_FAILED_ERROR, err
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@ -37,7 +37,7 @@ class FaradayTest < Minitest::Test
|
||||
def test_adapter_get_ssl_fails_with_bad_cert
|
||||
fake_store = OpenSSL::X509::Store.new
|
||||
conn = create_connection(ssl: { cert_store: fake_store, verify: OpenSSL::SSL::VERIFY_PEER })
|
||||
err = assert_raises Faraday::SSLError do
|
||||
err = assert_raises Faraday::Adapter::HTTPX::SSL_ERROR do
|
||||
conn.get(build_path("/get"))
|
||||
end
|
||||
assert_includes err.message, "certificate"
|
||||
@ -128,7 +128,7 @@ class FaradayTest < Minitest::Test
|
||||
# end
|
||||
|
||||
def test_adapter_connection_error
|
||||
assert_raises Faraday::Error::ConnectionFailed do
|
||||
assert_raises Faraday::Adapter::HTTPX::CONNECTION_FAILED_ERROR do
|
||||
get "http://localhost:4"
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user