Class: HTTPX::Resolver::HTTPS

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

Overview

Implementation of a DoH name resolver (www.youtube.com/watch?v=unMXvnY2FNM). It wraps an HTTPX::Connection object which integrates with the main session in the same manner as other performed HTTP requests.

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, #closed?, #each_connection, #early_resolve, #emit_addresses, #empty?, #force_close, #handle_error, #inflight?, multi?, #on_error

Methods included from Loggable

#log, #log_exception, #log_redact, #log_redact_body, #log_redact_headers

Constructor Details

#initialize(_, options) ⇒ HTTPS

Returns a new instance of HTTPS.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/httpx/resolver/https.rb', line 36

def initialize(_, options)
  super
  @resolver_options = DEFAULTS.merge(@options.resolver_options)
  @queries = {}
  @requests = {}
  @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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/httpx/resolver/https.rb', line 48

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_close
    throw(:resolve_error, ex)
  end

  resolve(connection)
end

#resolver_connectionObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/httpx/resolver/https.rb', line 63

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