class HTTPX::Resolver::Resolver

  1. lib/httpx/resolver/resolver.rb
Superclass: Object

Included modules

  1. Callbacks
  2. Loggable

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

Attributes

Public Class methods

multi?()
[show source]
   # File lib/httpx/resolver/resolver.rb
24 def multi?
25   true
26 end
new(family, options)
[show source]
   # File lib/httpx/resolver/resolver.rb
35 def initialize(family, options)
36   @family = family
37   @record_type = RECORD_TYPES[family]
38   @options = options
39 
40   set_resolver_callbacks
41 end

Public Instance methods

close()
[show source]
   # File lib/httpx/resolver/resolver.rb
51 def close; end
closed?()
[show source]
   # File lib/httpx/resolver/resolver.rb
55 def closed?
56   true
57 end
each_connection(&block)
[show source]
   # File lib/httpx/resolver/resolver.rb
43 def each_connection(&block)
44   enum_for(__method__) unless block
45 
46   return unless @connections
47 
48   @connections.each(&block)
49 end
emit_addresses(connection, family, addresses, early_resolve = false)
[show source]
   # File lib/httpx/resolver/resolver.rb
67 def emit_addresses(connection, family, addresses, early_resolve = false)
68   addresses.map! do |address|
69     address.is_a?(IPAddr) ? address : IPAddr.new(address.to_s)
70   end
71 
72   # double emission check, but allow early resolution to work
73   return if !early_resolve && connection.addresses && !addresses.intersect?(connection.addresses)
74 
75   log do
76     "resolver #{FAMILY_TYPES[RECORD_TYPES[family]]}: " \
77       "answer #{connection.peer.host}: #{addresses.inspect} (early resolve: #{early_resolve})"
78   end
79 
80   if !early_resolve && # do not apply resolution delay for non-dns name resolution
81      @current_selector && # just in case...
82      family == Socket::AF_INET && # resolution delay only applies to IPv4
83      !connection.io && # connection already has addresses and initiated/ended handshake
84      connection.options.ip_families.size > 1 && # no need to delay if not supporting dual stack IP
85      addresses.first.to_s != connection.peer.host.to_s # connection URL host is already the IP (early resolve included perhaps?)
86     log { "resolver #{FAMILY_TYPES[RECORD_TYPES[family]]}: applying resolution delay..." }
87 
88     @current_selector.after(0.05) do
89       # double emission check
90       unless connection.addresses && addresses.intersect?(connection.addresses)
91         emit_resolved_connection(connection, addresses, early_resolve)
92       end
93     end
94   else
95     emit_resolved_connection(connection, addresses, early_resolve)
96   end
97 end
empty?()
[show source]
   # File lib/httpx/resolver/resolver.rb
59 def empty?
60   true
61 end
inflight?()
[show source]
   # File lib/httpx/resolver/resolver.rb
63 def inflight?
64   false
65 end