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

Instance Attribute Summary

Attributes inherited from Resolver

#family, #pool

Instance Method Summary collapse

Methods inherited from Resolver

#close, #emit_addresses, multi?

Methods included from Loggable

#log, #log_exception

Methods included from Callbacks

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

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.origin.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
75
76
77
78
# File 'lib/httpx/resolver/https.rb', line 68

def resolver_connection
  @resolver_connection ||= @pool.find_connection(@uri, @options) || begin
    @building_connection = true
    connection = @options.connection_class.new(@uri, @options.merge(ssl: { alpn_protocols: %w[h2] }))
    @pool.init_connection(connection, @options)
    # only explicity emit addresses if connection didn't pre-resolve, i.e. it's not an IP.
    emit_addresses(connection, @family, @uri_addresses) unless connection.addresses
    @building_connection = false
    connection
  end
end