diff --git a/lib/httpx/connection.rb b/lib/httpx/connection.rb index 6b96c203..e5e69d94 100644 --- a/lib/httpx/connection.rb +++ b/lib/httpx/connection.rb @@ -540,7 +540,7 @@ module HTTPX if @total_timeout && @total_timeout.fires_in.negative? ex = TotalTimeoutError.new(@total_timeout.interval, "Timed out after #{@total_timeout.interval} seconds") - ex.set_backtrace(error.backtrace) if error.backtrace + ex.set_backtrace(error.backtrace) error = ex elsif connecting? error = error.to_connection_error diff --git a/lib/httpx/options.rb b/lib/httpx/options.rb index aea54f56..9cdc5469 100644 --- a/lib/httpx/options.rb +++ b/lib/httpx/options.rb @@ -111,7 +111,7 @@ module HTTPX def initialize(options = {}) defaults = DEFAULT_OPTIONS.merge(options) - defaults.each do |(k, v)| + defaults.each do |k, v| next if v.nil? begin @@ -185,6 +185,7 @@ module HTTPX end REQUEST_IVARS = %i[@params @form @json @body].freeze + private_constant :REQUEST_IVARS def ==(other) ivars = instance_variables | other.instance_variables @@ -202,7 +203,7 @@ module HTTPX end def merge(other) - raise ArgumentError, "#{other.inspect} is not a valid set of options" unless other.respond_to?(:to_hash) + raise ArgumentError, "#{other} is not a valid set of options" unless other.respond_to?(:to_hash) h2 = other.to_hash return self if h2.empty? diff --git a/lib/httpx/plugins/proxy.rb b/lib/httpx/plugins/proxy.rb index b724b304..832a5795 100644 --- a/lib/httpx/plugins/proxy.rb +++ b/lib/httpx/plugins/proxy.rb @@ -5,7 +5,8 @@ require "ipaddr" require "forwardable" module HTTPX - HTTPProxyError = Class.new(Error) + class HTTPProxyError < Error; end + module Plugins # # This plugin adds support for proxies. It ships with support for: @@ -136,10 +137,11 @@ module HTTPX def __proxy_error?(response) error = response.error case error - when ResolveError + when NativeResolveError # failed resolving proxy domain - proxy_uri = error.connection.options.proxy.uri - proxy_uri.to_s == @_proxy_uris.first + error.connection.origin.to_s == @_proxy_uris.first + when ResolveError + error.message.end_with?(@_proxy_uris.first) when *PROXY_ERRORS # timeout errors connecting to proxy true diff --git a/sig/connection.rbs b/sig/connection.rbs index df3e2e30..34c4beb2 100644 --- a/sig/connection.rbs +++ b/sig/connection.rbs @@ -26,6 +26,7 @@ module HTTPX attr_reader state: Symbol attr_reader pending: Array[Request] attr_reader options: Options + attr_writer timers: untyped # Timers::Timer def addresses: () -> Array[ipaddr]? @@ -37,7 +38,7 @@ module HTTPX def coalescable?: (Connection) -> bool - def create_idle: (?Hash[Symbol | String, untyped] options) -> Connection + def create_idle: (?Hash[Symbol, untyped] options) -> Connection def merge: (Connection) -> void diff --git a/sig/options.rbs b/sig/options.rbs index 86e396d7..87149618 100644 --- a/sig/options.rbs +++ b/sig/options.rbs @@ -45,7 +45,7 @@ module HTTPX attr_reader transport_options: Hash[untyped, untyped]? # addresses - attr_reader addresses: _ToAry[ipaddr]? + attr_reader addresses: Array[ipaddr]? # params attr_reader params: Transcoder::urlencoded_input? @@ -103,7 +103,7 @@ module HTTPX attr_reader resolver_options: Hash[Symbol, untyped]? def ==: (untyped other) -> bool - def merge: (_ToHash[Symbol | String, untyped] other) -> instance + def merge: (_ToHash[Symbol, untyped] other) -> instance def to_hash: () -> Hash[Symbol, untyped] private @@ -113,5 +113,5 @@ module HTTPX def initialize: (?options options) -> untyped end - type options = Options | Hash[Symbol | String, untyped] + type options = Options | Hash[Symbol, untyped] end