proxy: fixing proxy resolve error filtering to also work with system resolver

This commit is contained in:
HoneyryderChuck 2021-08-09 12:29:57 +01:00
parent 6b61b8ccdb
commit e1ee8c69dc
5 changed files with 15 additions and 11 deletions

View File

@ -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

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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