class HTTPX::Resolver::HTTPS

  1. lib/httpx/resolver/https.rb
Superclass: Resolver

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.

Methods

Public Class

  1. new

Public Instance

  1. <<
  2. resolver_connection
  3. state

Constants

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

Public Class methods

new(_, options)
[show source]
   # File lib/httpx/resolver/https.rb
38 def initialize(_, options)
39   super
40   @resolver_options = DEFAULTS.merge(@options.resolver_options)
41   @queries = {}
42   @requests = {}
43   @_timeouts = Array(@resolver_options[:timeouts])
44   @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup }
45   @uri = URI(@resolver_options[:uri])
46   @name = @uri_addresses = nil
47   @resolver = Resolv::DNS.new
48   @resolver.timeouts = @_timeouts.empty? ? Resolver::RESOLVE_TIMEOUT : @_timeouts
49   @resolver.lazy_initialize
50 end

Public Instance methods

<<(connection)
[show source]
   # File lib/httpx/resolver/https.rb
56 def <<(connection)
57   return if @uri.origin == connection.peer.to_s
58 
59   @uri_addresses ||= @options.resolver_cache.resolve(@uri.host) || @resolver.getaddresses(@uri.host)
60 
61   if @uri_addresses.empty?
62     ex = ResolveError.new("Can't resolve DNS server #{@uri.host}")
63     ex.set_backtrace(caller)
64     connection.force_close
65     throw(:resolve_error, ex)
66   end
67 
68   resolve(connection)
69 end
resolver_connection()
[show source]
   # File lib/httpx/resolver/https.rb
71 def resolver_connection
72   # TODO: leaks connection object into the pool
73   @resolver_connection ||=
74     @current_session.find_connection(
75       @uri,
76       @current_selector,
77       @options.merge(resolver_class: :system, ssl: { alpn_protocols: %w[h2] })
78     ).tap do |conn|
79       emit_addresses(conn, @family, @uri_addresses) unless conn.addresses
80       conn.on(:force_closed, &method(:force_close))
81     end
82 end
state()
[show source]
   # File lib/httpx/resolver/https.rb
52 def state
53   @resolver_connection ? @resolver_connection.state : :idle
54 end