Class: HTTPX::Resolver::Multi
- Inherits:
-
Object
- Object
- HTTPX::Resolver::Multi
show all
- Includes:
- Callbacks
- Defined in:
- lib/httpx/resolver/multi.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once
Constructor Details
#initialize(resolver_type, options) ⇒ Multi
Returns a new instance of Multi.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/httpx/resolver/multi.rb', line 13
def initialize(resolver_type, options)
@current_selector = @current_session = nil
@options = options
@resolver_options = @options.resolver_options
ip_families = options.ip_families || Resolver.supported_ip_families
@resolvers = ip_families.map do |ip_family|
resolver = resolver_type.new(ip_family, options)
resolver.multi = self
resolver
end
@errors = Hash.new { |hs, k| hs[k] = [] }
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/httpx/resolver/multi.rb', line 11
def options
@options
end
|
#resolvers ⇒ Object
Returns the value of attribute resolvers.
11
12
13
|
# File 'lib/httpx/resolver/multi.rb', line 11
def resolvers
@resolvers
end
|
Instance Method Details
#close ⇒ Object
59
60
61
|
# File 'lib/httpx/resolver/multi.rb', line 59
def close
@resolvers.each(&:close)
end
|
#closed? ⇒ Boolean
43
44
45
|
# File 'lib/httpx/resolver/multi.rb', line 43
def closed?
@resolvers.all?(&:closed?)
end
|
#connections ⇒ Object
63
64
65
|
# File 'lib/httpx/resolver/multi.rb', line 63
def connections
@resolvers.filter_map { |r| r.resolver_connection if r.respond_to?(:resolver_connection) }
end
|
#current_selector=(s) ⇒ Object
29
30
31
32
|
# File 'lib/httpx/resolver/multi.rb', line 29
def current_selector=(s)
@current_selector = s
@resolvers.each { |r| r.__send__(__method__, s) }
end
|
#current_session=(s) ⇒ Object
34
35
36
37
|
# File 'lib/httpx/resolver/multi.rb', line 34
def current_session=(s)
@current_session = s
@resolvers.each { |r| r.__send__(__method__, s) }
end
|
#early_resolve(connection) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/httpx/resolver/multi.rb', line 67
def early_resolve(connection)
hostname = connection.peer.host
addresses = @resolver_options[:cache] && (connection.addresses || HTTPX::Resolver.nolookup_resolve(hostname))
return false unless addresses
ip_families = connection.options.ip_families
resolved = false
addresses.group_by(&:family).sort { |(f1, _), (f2, _)| f2 <=> f1 }.each do |family, addrs|
next unless ip_families.nil? || ip_families.include?(family)
resolver = @resolvers.find { |r| r.family == family } || @resolvers.first
next unless resolver
resolver.emit_addresses(connection, family, addrs, true)
resolved = true
end
resolved
end
|
#empty? ⇒ Boolean
47
48
49
|
# File 'lib/httpx/resolver/multi.rb', line 47
def empty?
@resolvers.all?(&:empty?)
end
|
#inflight? ⇒ Boolean
51
52
53
|
# File 'lib/httpx/resolver/multi.rb', line 51
def inflight?
@resolvers.any(&:inflight?)
end
|
#lazy_resolve(connection) ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'lib/httpx/resolver/multi.rb', line 93
def lazy_resolve(connection)
@resolvers.each do |resolver|
resolver << @current_session.try_clone_connection(connection, @current_selector, resolver.family)
next if resolver.empty?
@current_session.select_resolver(resolver, @current_selector)
end
end
|
#log(*args, **kwargs, &blk) ⇒ Object
39
40
41
|
# File 'lib/httpx/resolver/multi.rb', line 39
def log(*args, **kwargs, &blk)
@resolvers.each { |r| r.__send__(__method__, *args, **kwargs, &blk) }
end
|
#timeout ⇒ Object
55
56
57
|
# File 'lib/httpx/resolver/multi.rb', line 55
def timeout
@resolvers.filter_map(&:timeout).min
end
|