lib/httpx/adapters/faraday.rb in httpx-0.24.7 vs lib/httpx/adapters/faraday.rb in httpx-1.0.0

- old
+ new

@@ -5,42 +5,15 @@ require "faraday" module Faraday class Adapter class HTTPX < Faraday::Adapter - # :nocov: - 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 - # :nocov: - - unless Faraday::RequestOptions.method_defined?(:stream_response?) - module RequestOptionsExtensions - refine Faraday::RequestOptions do - def stream_response? - false - end - end - end - using RequestOptionsExtensions - end - module RequestMixin - using ::HTTPX::HashExtensions - def build_connection(env) return @connection if defined?(@connection) - @connection = ::HTTPX.plugin(:compression).plugin(:persistent).plugin(ReasonPlugin) + @connection = ::HTTPX.plugin(:persistent).plugin(ReasonPlugin) @connection = @connection.with(@connection_options) unless @connection_options.empty? connection_opts = options_from_env(env) if (bind = env.request.bind) @bind = TCPSocket.new(bind[:host], bind[:port]) @@ -68,22 +41,20 @@ private def connect(env, &blk) connection(env, &blk) rescue ::HTTPX::TLSError => e - raise SSL_ERROR, e + raise Faraday::SSLError, e rescue Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EINVAL, Errno::ENETUNREACH, Errno::EPIPE, ::HTTPX::ConnectionError => e - raise CONNECTION_FAILED_ERROR, e - rescue ::HTTPX::TimeoutError => e - raise Faraday::TimeoutError, e + raise Faraday::ConnectionFailed, e end def build_request(env) meth = env[:method] @@ -157,28 +128,17 @@ end end end module ReasonPlugin - if RUBY_VERSION < "2.5" - def self.load_dependencies(*) - require "webrick" - end - else - def self.load_dependencies(*) - require "net/http/status" - end + def self.load_dependencies(*) + require "net/http/status" end + module ResponseMethods - if RUBY_VERSION < "2.5" - def reason - WEBrick::HTTPStatus::StatusMessage.fetch(@status) - end - else - def reason - Net::HTTP::STATUS_CODES.fetch(@status) - end + def reason + Net::HTTP::STATUS_CODES.fetch(@status) end end end class ParallelManager @@ -259,13 +219,10 @@ private # from Faraday::Adapter#request_timeout def request_timeout(type, options) - key = Faraday::Adapter::TIMEOUT_KEYS.fetch(type) do - msg = "Expected :read, :write, :open. Got #{type.inspect} :(" - raise ArgumentError, msg - end + key = Faraday::Adapter::TIMEOUT_KEYS[type] options[key] || options[:timeout] end end self.supports_parallel = true