class HTTPX::Resolver::Multi

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

Methods

Public Class

  1. new

Public Instance

  1. close
  2. closed?
  3. connections
  4. early_resolve
  5. resolvers
  6. timeout

Included modules

  1. Callbacks

Attributes

resolvers [R]

Public Class methods

new(resolver_type, options)
[show source]
   # File lib/httpx/resolver/multi.rb
13 def initialize(resolver_type, options)
14   @options = options
15   @resolver_options = @options.resolver_options
16 
17   @resolvers = options.ip_families.map do |ip_family|
18     resolver = resolver_type.new(ip_family, options)
19     resolver.on(:resolve, &method(:on_resolver_connection))
20     resolver.on(:error, &method(:on_resolver_error))
21     resolver.on(:close) { on_resolver_close(resolver) }
22     resolver
23   end
24 
25   @errors = Hash.new { |hs, k| hs[k] = [] }
26 end

Public Instance methods

close()
[show source]
   # File lib/httpx/resolver/multi.rb
36 def close
37   @resolvers.each(&:close)
38 end
closed?()
[show source]
   # File lib/httpx/resolver/multi.rb
28 def closed?
29   @resolvers.all?(&:closed?)
30 end
connections()
[show source]
   # File lib/httpx/resolver/multi.rb
40 def connections
41   @resolvers.filter_map { |r| r.resolver_connection if r.respond_to?(:resolver_connection) }
42 end
early_resolve(connection)
[show source]
   # File lib/httpx/resolver/multi.rb
44 def early_resolve(connection)
45   hostname = connection.origin.host
46   addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname))
47   return unless addresses
48 
49   addresses.group_by(&:family).sort { |(f1, _), (f2, _)| f2 <=> f1 }.each do |family, addrs|
50     # try to match the resolver by family. However, there are cases where that's not possible, as when
51     # the system does not have IPv6 connectivity, but it does support IPv6 via loopback/link-local.
52     resolver = @resolvers.find { |r| r.family == family } || @resolvers.first
53 
54     next unless resolver # this should ever happen
55 
56     # it does not matter which resolver it is, as early-resolve code is shared.
57     resolver.emit_addresses(connection, family, addrs, true)
58   end
59 end
timeout()
[show source]
   # File lib/httpx/resolver/multi.rb
32 def timeout
33   @resolvers.filter_map(&:timeout).min
34 end