From 69e41dc5dac2fa23f1fde9ba289c9e4605b6f029 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 27 Jul 2017 18:54:20 +0200 Subject: [PATCH] dns: enable usage of independent cares resolvers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: https://github.com/nodejs/node/issues/7231 PR-URL: https://github.com/nodejs/node/pull/14518 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen --- doc/api/dns.md | 45 ++++++++++++++ lib/dns.js | 83 ++++++++++++++----------- test/parallel/test-dns-multi-channel.js | 53 ++++++++++++++++ 3 files changed, 145 insertions(+), 36 deletions(-) create mode 100644 test/parallel/test-dns-multi-channel.js diff --git a/doc/api/dns.md b/doc/api/dns.md index d0d3071cc8d203..e9de95c118c573 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -54,6 +54,47 @@ dns.resolve4('archive.org', (err, addresses) => { There are subtle consequences in choosing one over the other, please consult the [Implementation considerations section][] for more information. +## Class dns.Resolver + + +An independent resolver for DNS requests. + +Note that creating a new resolver uses the default server settings. Setting +the servers used for a resolver using +[`resolver.setServers()`][`dns.setServers()`] does not affect +other resolver: + +```js +const { Resolver } = require('dns'); +const resolver = new Resolver(); +resolver.setServers(['4.4.4.4']); + +// This request will use the server at 4.4.4.4, independent of global settings. +resolver.resolve4('example.org', (err, addresses) => { + // ... +}); +``` + +The following methods from the `dns` module are available: + +* [`resolver.getServers()`][`dns.getServers()`] +* [`resolver.setServers()`][`dns.setServers()`] +* [`resolver.resolve()`][`dns.resolve()`] +* [`resolver.resolve4()`][`dns.resolve4()`] +* [`resolver.resolve6()`][`dns.resolve6()`] +* [`resolver.resolveAny()`][`dns.resolveAny()`] +* [`resolver.resolveCname()`][`dns.resolveCname()`] +* [`resolver.resolveMx()`][`dns.resolveMx()`] +* [`resolver.resolveNaptr()`][`dns.resolveNaptr()`] +* [`resolver.resolveNs()`][`dns.resolveNs()`] +* [`resolver.resolvePtr()`][`dns.resolvePtr()`] +* [`resolver.resolveSoa()`][`dns.resolveSoa()`] +* [`resolver.resolveSrv()`][`dns.resolveSrv()`] +* [`resolver.resolveTxt()`][`dns.resolveTxt()`] +* [`resolver.reverse()`][`dns.reverse()`] + ## dns.getServers()