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.
Classes and Modules
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 37 def initialize(_, options) 38 super 39 @resolver_options = DEFAULTS.merge(@options.resolver_options) 40 @queries = {} 41 @requests = {} 42 @_timeouts = Array(@resolver_options[:timeouts]) 43 @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup } 44 @uri = URI(@resolver_options[:uri]) 45 @name = @uri_addresses = nil 46 @resolver = Resolv::DNS.new 47 @resolver.timeouts = @_timeouts.empty? ? Resolver::RESOLVE_TIMEOUT : @_timeouts 48 @resolver.lazy_initialize 49 end
Public Instance methods
<<(connection)
[show source]
# File lib/httpx/resolver/https.rb 55 def <<(connection) 56 return if @uri.origin == connection.peer.to_s 57 58 @uri_addresses ||= @options.resolver_cache.resolve(@uri.host) || @resolver.getaddresses(@uri.host) 59 60 if @uri_addresses.empty? 61 ex = ResolveError.new("Can't resolve DNS server #{@uri.host}") 62 ex.set_backtrace(caller) 63 connection.force_close 64 throw(:resolve_error, ex) 65 end 66 67 resolve(connection) 68 end
resolver_connection()
[show source]
# File lib/httpx/resolver/https.rb 70 def resolver_connection 71 # TODO: leaks connection object into the pool 72 @resolver_connection ||= 73 @current_session.find_connection( 74 @uri, 75 @current_selector, 76 @options.merge(resolver_class: :system, ssl: { alpn_protocols: %w[h2] }) 77 ).tap do |conn| 78 emit_addresses(conn, @family, @uri_addresses) unless conn.addresses 79 conn.on(:force_closed, &method(:force_close)) 80 end 81 end
state()
[show source]
# File lib/httpx/resolver/https.rb 51 def state 52 @resolver_connection ? @resolver_connection.state : :idle 53 end