lib/httpx/adapters/faraday.rb in httpx-0.4.1 vs lib/httpx/adapters/faraday.rb in httpx-0.5.0

- old
+ new

@@ -4,10 +4,22 @@ 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 def build_request(env) meth = env[:method] @@ -138,11 +150,11 @@ session = @session.with(options_from_env(env)) session = session.plugin(:proxy).with_proxy(proxy_options) if env.request.proxy responses = session.request(requests) - responses.each_with_index do |response, index| + Array(responses).each_with_index do |response, index| handler = @handlers[index] handler.on_response.call(response) handler.on_complete.call(handler.env) end end @@ -160,14 +172,15 @@ super(app) @session = Session.new end def call(env) + super if parallel?(env) handler = env[:parallel_manager].enqueue(env) handler.on_response do |response| - save_response(env, response.status, response.body, response.headers, response.reason) do |response_headers| + save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| response_headers.merge!(response.headers) end end return handler end @@ -176,23 +189,23 @@ session = @session.with(options_from_env(env)) session = session.plugin(:proxy).with_proxy(proxy_options) if env.request.proxy response = session.__send__(*request_options) response.raise_for_status unless response.is_a?(::HTTPX::Response) - save_response(env, response.status, response.body, response.headers, response.reason) do |response_headers| + save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| response_headers.merge!(response.headers) end @app.call(env) rescue OpenSSL::SSL::SSLError => err - raise Error::SSLError, err + raise SSL_ERROR, err rescue Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EINVAL, Errno::ENETUNREACH, Errno::EPIPE => err - raise Error::ConnectionFailed, err + raise CONNECTION_FAILED_ERROR, err end private def parallel?(env)