class HTTPX::Resolver::Multi

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

Attributes

options [R]
resolvers [R]

Public Class methods

new(resolver_type, options)
[show source]
   # File lib/httpx/resolver/multi.rb
10 def initialize(resolver_type, options)
11   @current_selector = @current_session = nil
12   @options = options
13   @resolver_options = @options.resolver_options
14 
15   ip_families = options.ip_families || Resolver.supported_ip_families
16 
17   @resolvers = ip_families.map do |ip_family|
18     resolver = resolver_type.new(ip_family, options)
19     resolver.multi = self
20     resolver
21   end
22 
23   @errors = Hash.new { |hs, k| hs[k] = [] }
24 end

Public Instance methods

closed?()
[show source]
   # File lib/httpx/resolver/multi.rb
40 def closed?
41   @resolvers.all?(&:closed?)
42 end
current_selector=(s)
[show source]
   # File lib/httpx/resolver/multi.rb
26 def current_selector=(s)
27   @current_selector = s
28   @resolvers.each { |r| r.current_selector = s }
29 end
current_session=(s)
[show source]
   # File lib/httpx/resolver/multi.rb
31 def current_session=(s)
32   @current_session = s
33   @resolvers.each { |r| r.current_session = s }
34 end
early_resolve(connection)
[show source]
   # File lib/httpx/resolver/multi.rb
44 def early_resolve(connection)
45   hostname = connection.peer.host
46   addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname))
47   return false unless addresses
48 
49   ip_families = connection.options.ip_families
50 
51   resolved = false
52   addresses.group_by(&:family).sort { |(f1, _), (f2, _)| f2 <=> f1 }.each do |family, addrs|
53     next unless ip_families.nil? || ip_families.include?(family)
54 
55     # try to match the resolver by family. However, there are cases where that's not possible, as when
56     # the system does not have IPv6 connectivity, but it does support IPv6 via loopback/link-local.
57     resolver = @resolvers.find { |r| r.family == family } || @resolvers.first
58 
59     next unless resolver # this should ever happen
60 
61     # it does not matter which resolver it is, as early-resolve code is shared.
62     resolver.emit_addresses(connection, family, addrs, true)
63 
64     resolved = true
65   end
66 
67   resolved
68 end
lazy_resolve(connection)
[show source]
   # File lib/httpx/resolver/multi.rb
70 def lazy_resolve(connection)
71   @resolvers.each do |resolver|
72     conn_to_resolve = @current_session.try_clone_connection(connection, @current_selector, resolver.family)
73     resolver << conn_to_resolve
74 
75     next if resolver.empty?
76 
77     # both the resolver and the connection it's resolving must be pineed to the session
78     @current_session.pin(conn_to_resolve, @current_selector)
79     @current_session.select_resolver(resolver, @current_selector)
80   end
81 end
log(*args, **kwargs, &blk)
[show source]
   # File lib/httpx/resolver/multi.rb
36 def log(*args, **kwargs, &blk)
37   @resolvers.each { |r| r.log(*args, **kwargs, &blk) }
38 end