Skip to content

Commit

Permalink
dns: expose getDefaultResultOrder
Browse files Browse the repository at this point in the history
PR-URL: #46973
Fixes: #46919
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
  • Loading branch information
btea authored Apr 26, 2023
1 parent 71a776b commit 2ac5e98
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/api/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,18 @@ priority than [`--dns-result-order`][]. When using [worker threads][],
[`dns.setDefaultResultOrder()`][] from the main thread won't affect the default
dns orders in workers.

## `dns.getDefaultResultOrder()`

<!-- YAML
added: REPLACEME
-->

Get the default value for `verbatim` in [`dns.lookup()`][] and
[`dnsPromises.lookup()`][]. The value could be:

* `ipv4first`: for `verbatim` defaulting to `false`.
* `verbatim`: for `verbatim` defaulting to `true`.

## `dns.setServers(servers)`

<!-- YAML
Expand Down Expand Up @@ -1351,6 +1363,14 @@ higher priority than [`--dns-result-order`][]. When using [worker threads][],
[`dnsPromises.setDefaultResultOrder()`][] from the main thread won't affect the
default dns orders in workers.

### `dnsPromises.getDefaultResultOrder()`

<!-- YAML
added: REPLACEME
-->

Get the value of `dnsOrder`.

### `dnsPromises.setServers(servers)`

<!-- YAML
Expand Down
2 changes: 2 additions & 0 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const {
validateHints,
emitInvalidHostnameWarning,
getDefaultVerbatim,
getDefaultResultOrder,
setDefaultResultOrder,
errorCodes: dnsErrorCodes,
} = require('internal/dns/utils');
Expand Down Expand Up @@ -305,6 +306,7 @@ module.exports = {
lookupService,

Resolver,
getDefaultResultOrder,
setDefaultResultOrder,
setServers: defaultResolverSetServers,

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
emitInvalidHostnameWarning,
getDefaultVerbatim,
errorCodes: dnsErrorCodes,
getDefaultResultOrder,
setDefaultResultOrder,
setDefaultResolver,
} = require('internal/dns/utils');
Expand Down Expand Up @@ -335,6 +336,7 @@ module.exports = {
lookup,
lookupService,
Resolver,
getDefaultResultOrder,
setDefaultResultOrder,
setServers: defaultResolverSetServers,

Expand Down
5 changes: 5 additions & 0 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ function setDefaultResultOrder(value) {
dnsOrder = value;
}

function getDefaultResultOrder() {
return dnsOrder;
}

function createResolverClass(resolver) {
const resolveMap = { __proto__: null };

Expand Down Expand Up @@ -346,6 +350,7 @@ module.exports = {
validateTries,
emitInvalidHostnameWarning,
getDefaultVerbatim,
getDefaultResultOrder,
setDefaultResultOrder,
errorCodes,
createResolverClass,
Expand Down
24 changes: 24 additions & 0 deletions test/internet/test-dns-getDefaultResultOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const common = require('../common');

const assert = require('assert');
const dns = require('dns');

dns.setDefaultResultOrder('ipv4first');
let dnsOrder = dns.getDefaultResultOrder();
assert.ok(dnsOrder === 'ipv4first');
dns.setDefaultResultOrder('verbatim');
dnsOrder = dns.getDefaultResultOrder();
assert.ok(dnsOrder === 'verbatim');

{
(async function() {
const result = await dns.promises.lookup('localhost');
const result1 = await dns.promises.lookup('localhost', { verbatim: true });
assert.ok(result !== undefined);
assert.ok(result1 !== undefined);
assert.ok(result.address === result1.address);
assert.ok(result.family === result1.family);
})().then(common.mustCall());
}

0 comments on commit 2ac5e98

Please sign in to comment.