Class: HTTPX::Resolver::Resolver
- Inherits:
-
Object
- Object
- HTTPX::Resolver::Resolver
- Defined in:
- lib/httpx/resolver/resolver.rb
Overview
Base class for all internal internet name resolvers. It handles basic blocks from the Selectable API.
Constant Summary collapse
- RECORD_TYPES =
{ Socket::AF_INET6 => Resolv::DNS::Resource::IN::AAAA, Socket::AF_INET => Resolv::DNS::Resource::IN::A, }.freeze
- FAMILY_TYPES =
{ Resolv::DNS::Resource::IN::AAAA => "AAAA", Resolv::DNS::Resource::IN::A => "A", }.freeze
Constants included from Loggable
Loggable::COLORS, Loggable::USE_DEBUG_LOG
Instance Attribute Summary collapse
-
#current_selector ⇒ Object
writeonly
Sets the attribute current_selector.
-
#current_session ⇒ Object
writeonly
Sets the attribute current_session.
-
#family ⇒ Object
readonly
Returns the value of attribute family.
-
#multi ⇒ Object
Returns the value of attribute multi.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object (also: #terminate)
- #closed? ⇒ Boolean
- #each_connection(&block) ⇒ Object
- #emit_addresses(connection, family, addresses, early_resolve = false) ⇒ Object
- #empty? ⇒ Boolean
- #inflight? ⇒ Boolean
-
#initialize(family, options) ⇒ Resolver
constructor
A new instance of Resolver.
Methods included from Loggable
#log, #log_exception, #log_redact
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once
Constructor Details
#initialize(family, options) ⇒ Resolver
Returns a new instance of Resolver.
38 39 40 41 42 43 44 45 |
# File 'lib/httpx/resolver/resolver.rb', line 38 def initialize(family, ) @family = family @record_type = RECORD_TYPES[family] @options = @connections = [] set_resolver_callbacks end |
Instance Attribute Details
#current_selector=(value) ⇒ Object (writeonly)
Sets the attribute current_selector
34 35 36 |
# File 'lib/httpx/resolver/resolver.rb', line 34 def current_selector=(value) @current_selector = value end |
#current_session=(value) ⇒ Object (writeonly)
Sets the attribute current_session
34 35 36 |
# File 'lib/httpx/resolver/resolver.rb', line 34 def current_session=(value) @current_session = value end |
#family ⇒ Object (readonly)
Returns the value of attribute family.
32 33 34 |
# File 'lib/httpx/resolver/resolver.rb', line 32 def family @family end |
#multi ⇒ Object
Returns the value of attribute multi.
36 37 38 |
# File 'lib/httpx/resolver/resolver.rb', line 36 def multi @multi end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/httpx/resolver/resolver.rb', line 32 def @options end |
Class Method Details
.multi? ⇒ Boolean
27 28 29 |
# File 'lib/httpx/resolver/resolver.rb', line 27 def multi? true end |
Instance Method Details
#close ⇒ Object Also known as: terminate
55 |
# File 'lib/httpx/resolver/resolver.rb', line 55 def close; end |
#closed? ⇒ Boolean
59 60 61 |
# File 'lib/httpx/resolver/resolver.rb', line 59 def closed? true end |
#each_connection(&block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/httpx/resolver/resolver.rb', line 47 def each_connection(&block) enum_for(__method__) unless block return unless @connections @connections.each(&block) end |
#emit_addresses(connection, family, addresses, early_resolve = false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/httpx/resolver/resolver.rb', line 71 def emit_addresses(connection, family, addresses, early_resolve = false) addresses.map! do |address| address.is_a?(IPAddr) ? address : IPAddr.new(address.to_s) end # double emission check, but allow early resolution to work return if !early_resolve && connection.addresses && !addresses.intersect?(connection.addresses) log do "resolver #{FAMILY_TYPES[RECORD_TYPES[family]]}: " \ "answer #{connection.peer.host}: #{addresses.inspect} (early resolve: #{early_resolve})" end if !early_resolve && # do not apply resolution delay for non-dns name resolution @current_selector && # just in case... family == Socket::AF_INET && # resolution delay only applies to IPv4 !connection.io && # connection already has addresses and initiated/ended handshake connection..ip_families.size > 1 && # no need to delay if not supporting dual stack IP addresses.first.to_s != connection.peer.host.to_s # connection URL host is already the IP (early resolve included perhaps?) log { "resolver #{FAMILY_TYPES[RECORD_TYPES[family]]}: applying resolution delay..." } @current_selector.after(0.05) do # double emission check unless connection.addresses && addresses.intersect?(connection.addresses) emit_resolved_connection(connection, addresses, early_resolve) end end else emit_resolved_connection(connection, addresses, early_resolve) end end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/httpx/resolver/resolver.rb', line 63 def empty? true end |
#inflight? ⇒ Boolean
67 68 69 |
# File 'lib/httpx/resolver/resolver.rb', line 67 def inflight? false end |