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? if @total_timeout && @total_timeout.fires_in.negative?
ex = TotalTimeoutError.new(@total_timeout.interval, "Timed out after #{@total_timeout.interval} seconds") 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 error = ex
elsif connecting? elsif connecting?
error = error.to_connection_error error = error.to_connection_error

View File

@ -111,7 +111,7 @@ module HTTPX
def initialize(options = {}) def initialize(options = {})
defaults = DEFAULT_OPTIONS.merge(options) defaults = DEFAULT_OPTIONS.merge(options)
defaults.each do |(k, v)| defaults.each do |k, v|
next if v.nil? next if v.nil?
begin begin
@ -185,6 +185,7 @@ module HTTPX
end end
REQUEST_IVARS = %i[@params @form @json @body].freeze REQUEST_IVARS = %i[@params @form @json @body].freeze
private_constant :REQUEST_IVARS
def ==(other) def ==(other)
ivars = instance_variables | other.instance_variables ivars = instance_variables | other.instance_variables
@ -202,7 +203,7 @@ module HTTPX
end end
def merge(other) 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 h2 = other.to_hash
return self if h2.empty? return self if h2.empty?

View File

@ -5,7 +5,8 @@ require "ipaddr"
require "forwardable" require "forwardable"
module HTTPX module HTTPX
HTTPProxyError = Class.new(Error) class HTTPProxyError < Error; end
module Plugins module Plugins
# #
# This plugin adds support for proxies. It ships with support for: # This plugin adds support for proxies. It ships with support for:
@ -136,10 +137,11 @@ module HTTPX
def __proxy_error?(response) def __proxy_error?(response)
error = response.error error = response.error
case error case error
when ResolveError when NativeResolveError
# failed resolving proxy domain # failed resolving proxy domain
proxy_uri = error.connection.options.proxy.uri error.connection.origin.to_s == @_proxy_uris.first
proxy_uri.to_s == @_proxy_uris.first when ResolveError
error.message.end_with?(@_proxy_uris.first)
when *PROXY_ERRORS when *PROXY_ERRORS
# timeout errors connecting to proxy # timeout errors connecting to proxy
true true

View File

@ -26,6 +26,7 @@ module HTTPX
attr_reader state: Symbol attr_reader state: Symbol
attr_reader pending: Array[Request] attr_reader pending: Array[Request]
attr_reader options: Options attr_reader options: Options
attr_writer timers: untyped # Timers::Timer
def addresses: () -> Array[ipaddr]? def addresses: () -> Array[ipaddr]?
@ -37,7 +38,7 @@ module HTTPX
def coalescable?: (Connection) -> bool 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 def merge: (Connection) -> void

View File

@ -45,7 +45,7 @@ module HTTPX
attr_reader transport_options: Hash[untyped, untyped]? attr_reader transport_options: Hash[untyped, untyped]?
# addresses # addresses
attr_reader addresses: _ToAry[ipaddr]? attr_reader addresses: Array[ipaddr]?
# params # params
attr_reader params: Transcoder::urlencoded_input? attr_reader params: Transcoder::urlencoded_input?
@ -103,7 +103,7 @@ module HTTPX
attr_reader resolver_options: Hash[Symbol, untyped]? attr_reader resolver_options: Hash[Symbol, untyped]?
def ==: (untyped other) -> bool 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] def to_hash: () -> Hash[Symbol, untyped]
private private
@ -113,5 +113,5 @@ module HTTPX
def initialize: (?options options) -> untyped def initialize: (?options options) -> untyped
end end
type options = Options | Hash[Symbol | String, untyped] type options = Options | Hash[Symbol, untyped]
end end