lib/httpx/resolver/native.rb in httpx-0.9.0 vs lib/httpx/resolver/native.rb in httpx-0.10.0
- old
+ new
@@ -5,10 +5,11 @@
module HTTPX
class Resolver::Native
extend Forwardable
include Resolver::ResolverMixin
+ using URIExtensions
RESOLVE_TIMEOUT = 5
RECORD_TYPES = {
"A" => Resolv::DNS::Resource::IN::A,
"AAAA" => Resolv::DNS::Resource::IN::AAAA,
@@ -166,11 +167,10 @@
def dread(wsize = @resolver_options.packet_size)
loop do
siz = @io.read(wsize, @read_buffer)
return unless siz && siz.positive?
- log { "resolver: READ: #{siz} bytes..." }
parse(@read_buffer)
return if @state == :closed
end
end
@@ -179,11 +179,10 @@
return if @write_buffer.empty?
siz = @io.write(@write_buffer)
return unless siz && siz.positive?
- log { "resolver: WRITE: #{siz} bytes..." }
return if @state == :closed
end
end
def parse(buffer)
@@ -235,10 +234,15 @@
def resolve(connection = @connections.first, hostname = nil)
raise Error, "no URI to resolve" unless connection
return unless @write_buffer.empty?
- hostname = hostname || @queries.key(connection) || connection.origin.host
+ hostname ||= @queries.key(connection)
+
+ if hostname.nil?
+ hostname = connection.origin.host
+ log { "resolver: resolve IDN #{connection.origin.non_ascii_hostname} as #{hostname}" } if connection.origin.non_ascii_hostname
+ end
@queries[hostname] = connection
type = @_record_types[hostname].first
log { "resolver: query #{type} for #{hostname}" }
begin
@write_buffer << Resolver.encode_dns_query(hostname, type: RECORD_TYPES[type])