mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
Two resolver are kept (IPv6/IPv4) along in the pool, to which all names are sent to and read from in the same pool. IPv4 resolves are subject to a 50ms delay (as per rfc) before they're used for connecting. IPv6 addresses have preference, in that if they arrive before the delay, they are immediately used. If they arrive after the delay, they do not interrupt the connection, but they'll be the next-in-line in case connection handshake fails. Two resolvers are kept, but the inherent Connection will be shared, thereby sending name resolving requests to the same HTTP/2 connection in bulk. The resolution delay logic from above also applies. Currently handles resolving via `resolv` lib. This happens synchronously though, so we're not there yet.
33 lines
1.2 KiB
Ruby
33 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "test_helper"
|
|
|
|
class ResolverTest < Minitest::Test
|
|
include HTTPX
|
|
|
|
def test_cached_lookup
|
|
ips = Resolver.cached_lookup("test.com")
|
|
assert ips.nil?
|
|
dns_entry = { "data" => "IPv6", "TTL" => 2, "name" => "test.com" }
|
|
Resolver.cached_lookup_set("test.com", Socket::AF_INET6, [dns_entry])
|
|
ips = Resolver.cached_lookup("test.com")
|
|
assert ips == ["IPv6"]
|
|
sleep 2
|
|
ips = Resolver.cached_lookup("test.com")
|
|
assert ips.nil?
|
|
alias_entry = { "alias" => "test.com", "TTL" => 2, "name" => "foo.com" }
|
|
Resolver.cached_lookup_set("test.com", Socket::AF_INET6, [dns_entry])
|
|
Resolver.cached_lookup_set("foo.com", Socket::AF_INET6, [alias_entry])
|
|
ips = Resolver.cached_lookup("foo.com")
|
|
assert ips == ["IPv6"]
|
|
|
|
Resolver.cached_lookup_set("test.com", Socket::AF_INET6, [{ "data" => "IPv6_2", "TTL" => 2, "name" => "test.com" }])
|
|
ips = Resolver.cached_lookup("test.com")
|
|
assert ips == %w[IPv6 IPv6_2]
|
|
|
|
Resolver.cached_lookup_set("test.com", Socket::AF_INET, [{ "data" => "IPv4", "TTL" => 2, "name" => "test.com" }])
|
|
ips = Resolver.cached_lookup("test.com")
|
|
assert ips == %w[IPv4 IPv6 IPv6_2]
|
|
end
|
|
end
|