Constants
FAMILY_TYPES | = | { Resolv::DNS::Resource::IN::AAAA => "AAAA", Resolv::DNS::Resource::IN::A => "A", }.freeze | ||
RECORD_TYPES | = | { Socket::AF_INET6 => Resolv::DNS::Resource::IN::AAAA, Socket::AF_INET => Resolv::DNS::Resource::IN::A, }.freeze |
Public Instance Aliases
terminate | -> | close |
Public Class methods
new(family, options)
[show source]
# File lib/httpx/resolver/resolver.rb 33 def initialize(family, options) 34 @family = family 35 @record_type = RECORD_TYPES[family] 36 @options = options 37 end
Public Instance methods
emit_addresses(connection, family, addresses, early_resolve = false)
[show source]
# File lib/httpx/resolver/resolver.rb 51 def emit_addresses(connection, family, addresses, early_resolve = false) 52 addresses.map! do |address| 53 address.is_a?(IPAddr) ? address : IPAddr.new(address.to_s) 54 end 55 56 # double emission check, but allow early resolution to work 57 return if !early_resolve && connection.addresses && !addresses.intersect?(connection.addresses) 58 59 log { "resolver: answer #{FAMILY_TYPES[RECORD_TYPES[family]]} #{connection.origin.host}: #{addresses.inspect}" } 60 if @pool && # if triggered by early resolve, pool may not be here yet 61 !connection.io && 62 connection.options.ip_families.size > 1 && 63 family == Socket::AF_INET && 64 addresses.first.to_s != connection.origin.host.to_s 65 log { "resolver: A response, applying resolution delay..." } 66 @pool.after(0.05) do 67 unless connection.state == :closed || 68 # double emission check 69 (connection.addresses && addresses.intersect?(connection.addresses)) 70 emit_resolved_connection(connection, addresses, early_resolve) 71 end 72 end 73 else 74 emit_resolved_connection(connection, addresses, early_resolve) 75 end 76 end