Class: HTTPX::Resolver::HTTPS

Inherits:
Resolver
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/httpx/resolver/https.rb

Defined Under Namespace

Modules: DNSExtensions

Constant Summary collapse

NAMESERVER =
"https://1.1.1.1/dns-query"
DEFAULTS =
{
  uri: NAMESERVER,
  use_get: false,
}.freeze

Constants inherited from Resolver

Resolver::FAMILY_TYPES, Resolver::RECORD_TYPES

Constants included from Loggable

Loggable::COLORS, Loggable::USE_DEBUG_LOG

Instance Attribute Summary

Attributes inherited from Resolver

#current_selector, #current_session, #family, #multi, #options

Instance Method Summary collapse

Methods inherited from Resolver

#close, #each_connection, #emit_addresses, #inflight?, multi?

Methods included from Loggable

#log, #log_exception

Methods included from Callbacks

#callbacks_for?, #emit, #on, #once

Constructor Details

#initialize(_, options) ⇒ HTTPS

Returns a new instance of HTTPS.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/httpx/resolver/https.rb', line 32

def initialize(_, options)
  super
  @resolver_options = DEFAULTS.merge(@options.resolver_options)
  @queries = {}
  @requests = {}
  @connections = []
  @uri = URI(@resolver_options[:uri])
  @uri_addresses = nil
  @resolver = Resolv::DNS.new
  @resolver.timeouts = @resolver_options.fetch(:timeouts, Resolver::RESOLVE_TIMEOUT)
  @resolver.lazy_initialize
end

Instance Method Details

#<<(connection) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/httpx/resolver/https.rb', line 45

def <<(connection)
  return if @uri.origin == connection.peer.to_s

  @uri_addresses ||= HTTPX::Resolver.nolookup_resolve(@uri.host) || @resolver.getaddresses(@uri.host)

  if @uri_addresses.empty?
    ex = ResolveError.new("Can't resolve DNS server #{@uri.host}")
    ex.set_backtrace(caller)
    connection.force_reset
    throw(:resolve_error, ex)
  end

  resolve(connection)
end

#closed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/httpx/resolver/https.rb', line 60

def closed?
  true
end

#empty?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/httpx/resolver/https.rb', line 64

def empty?
  true
end

#resolver_connectionObject



68
69
70
71
72
73
74
# File 'lib/httpx/resolver/https.rb', line 68

def resolver_connection
  # TODO: leaks connection object into the pool
  @resolver_connection ||= @current_session.find_connection(@uri, @current_selector,
                                                            @options.merge(ssl: { alpn_protocols: %w[h2] })).tap do |conn|
    emit_addresses(conn, @family, @uri_addresses) unless conn.addresses
  end
end