lib/httpx/resolver/https.rb in httpx-0.6.3 vs lib/httpx/resolver/https.rb in httpx-0.6.4

- old
+ new

@@ -7,10 +7,11 @@ module HTTPX class Resolver::HTTPS extend Forwardable include Resolver::ResolverMixin + using URIExtensions NAMESERVER = "https://1.1.1.1/dns-query" RECORD_TYPES = { "A" => Resolv::DNS::Resource::IN::A, @@ -36,11 +37,14 @@ @uri = URI(@resolver_options.uri) @uri_addresses = nil end def <<(connection) + return if @uri.origin == connection.origin.to_s + @uri_addresses ||= Resolv.getaddresses(@uri.host) + if @uri_addresses.empty? ex = ResolveError.new("Can't resolve #{connection.origin.host}") ex.set_backtrace(caller) emit(:error, connection, ex) else @@ -92,15 +96,15 @@ end end def on_response(request, response) response.raise_for_status - rescue Error => ex + rescue StandardError => e connection = @requests[request] hostname = @queries.key(connection) - error = ResolveError.new("Can't resolve #{hostname}: #{ex.message}") - error.set_backtrace(ex.backtrace) + error = ResolveError.new("Can't resolve #{hostname}: #{e.message}") + error.set_backtrace(e.backtrace) emit(:error, connection, error) else parse(response) ensure @requests.delete(request) @@ -174,11 +178,11 @@ request = rklass.new("GET", uri, @options) else payload = Resolver.encode_dns_query(hostname, type: RECORD_TYPES[type]) request = rklass.new("POST", uri, @options.merge(body: [payload])) request.headers["content-type"] = "application/dns-message" - request.headers["accept"] = "application/dns-message" end + request.headers["accept"] = "application/dns-message" request.on(:response, &method(:on_response).curry[request]) request.on(:promise, &method(:on_promise)) request end