Class: HTTPX::Resolver::Multi
- Inherits:
-
Object
- Object
- HTTPX::Resolver::Multi
- Defined in:
- lib/httpx/resolver/multi.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#resolvers ⇒ Object
readonly
Returns the value of attribute resolvers.
Instance Method Summary collapse
- #closed? ⇒ Boolean
- #current_selector=(s) ⇒ Object
- #current_session=(s) ⇒ Object
- #early_resolve(connection) ⇒ Object
-
#initialize(resolver_type, options) ⇒ Multi
constructor
A new instance of Multi.
- #lazy_resolve(connection) ⇒ Object
- #log(*args, **kwargs, &blk) ⇒ Object
Constructor Details
#initialize(resolver_type, options) ⇒ Multi
Returns a new instance of Multi.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/httpx/resolver/multi.rb', line 10 def initialize(resolver_type, ) @current_selector = @current_session = nil @options = @resolver_options = @options. ip_families = .ip_families || Resolver.supported_ip_families @resolvers = ip_families.map do |ip_family| resolver = resolver_type.new(ip_family, ) resolver.multi = self resolver end @errors = Hash.new { |hs, k| hs[k] = [] } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/httpx/resolver/multi.rb', line 8 def @options end |
#resolvers ⇒ Object (readonly)
Returns the value of attribute resolvers.
8 9 10 |
# File 'lib/httpx/resolver/multi.rb', line 8 def resolvers @resolvers end |
Instance Method Details
#closed? ⇒ Boolean
40 41 42 |
# File 'lib/httpx/resolver/multi.rb', line 40 def closed? @resolvers.all?(&:closed?) end |
#current_selector=(s) ⇒ Object
26 27 28 29 |
# File 'lib/httpx/resolver/multi.rb', line 26 def current_selector=(s) @current_selector = s @resolvers.each { |r| r.current_selector = s } end |
#current_session=(s) ⇒ Object
31 32 33 34 |
# File 'lib/httpx/resolver/multi.rb', line 31 def current_session=(s) @current_session = s @resolvers.each { |r| r.current_session = s } end |
#early_resolve(connection) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/httpx/resolver/multi.rb', line 44 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..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) # try to match the resolver by family. However, there are cases where that's not possible, as when # the system does not have IPv6 connectivity, but it does support IPv6 via loopback/link-local. resolver = @resolvers.find { |r| r.family == family } || @resolvers.first next unless resolver # this should ever happen # it does not matter which resolver it is, as early-resolve code is shared. resolver.emit_addresses(connection, family, addrs, true) resolved = true end resolved end |
#lazy_resolve(connection) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/httpx/resolver/multi.rb', line 70 def lazy_resolve(connection) @resolvers.each do |resolver| conn_to_resolve = @current_session.try_clone_connection(connection, @current_selector, resolver.family) resolver << conn_to_resolve next if resolver.empty? # both the resolver and the connection it's resolving must be pineed to the session @current_session.pin(conn_to_resolve, @current_selector) @current_session.select_resolver(resolver, @current_selector) end end |
#log(*args, **kwargs, &blk) ⇒ Object
36 37 38 |
# File 'lib/httpx/resolver/multi.rb', line 36 def log(*args, **kwargs, &blk) @resolvers.each { |r| r.log(*args, **kwargs, &blk) } end |