httpx/test/support/session_with_pool.rb
HoneyryderChuck c1281a9074 native resolver: switch from nameserver if dns query fails
a behaviour has been observed behind a vpn, where when one of the
servers is unresponsive, the switch to the next nameserver wasn't
happening. Part of it was a bug in the timeout handling, but the rest
was actually the switch not happening (i.e. it'd fail on the first
server). This fixes it by switching to the next nammeserver on query
error.
2022-09-20 23:11:08 +01:00

55 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module SessionWithPool
ConnectionPool = Class.new(HTTPX::Pool) do
attr_reader :resolver, :connections, :selector
attr_reader :connection_count
attr_reader :ping_count
def initialize(*)
super
@connection_count = 0
@ping_count = 0
end
def init_connection(connection, _)
super
connection.on(:open) { @connection_count += 1 }
connection.on(:pong) { @ping_count += 1 }
end
def selectable_count
@selector.instance_variable_get(:@selectables).size
end
def find_resolver_for(*args, &blk)
@resolver = super(*args, &blk)
@resolver
end
end
module InstanceMethods
attr_reader :connection_exausted
def pool
@pool ||= ConnectionPool.new
end
def set_connection_callbacks(connection, connections, options)
super
connection.on(:exhausted) do
@connection_exausted = true
end
end
end
module ConnectionMethods
attr_reader :origins
def set_parser_callbacks(parser)
super
parser.on(:pong) { emit(:pong) }
end
end
end