mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-15 00:00:39 -04:00
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.
55 lines
1.1 KiB
Ruby
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
|