Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: expose getDefaultResultOrder #46973

Merged
merged 7 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()`
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

<!-- 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()`
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

<!-- 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());
}