From 382dcf1bb4d9044741c27f93eea4ea0299642d0e Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 6 Mar 2023 20:21:27 +0800 Subject: [PATCH 1/7] dns: expose getDefaultResultOrder --- lib/dns.js | 2 ++ lib/internal/dns/promises.js | 2 ++ lib/internal/dns/utils.js | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/lib/dns.js b/lib/dns.js index c0e6a3332e4d21..ae0e14bab3097d 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -38,6 +38,7 @@ const { validateHints, emitInvalidHostnameWarning, getDefaultVerbatim, + getDefaultResultOrder, setDefaultResultOrder, errorCodes: dnsErrorCodes, } = require('internal/dns/utils'); @@ -305,6 +306,7 @@ module.exports = { lookupService, Resolver, + getDefaultResultOrder, setDefaultResultOrder, setServers: defaultResolverSetServers, diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 494c7ecb242c7b..df41d1267ef421 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -14,6 +14,7 @@ const { emitInvalidHostnameWarning, getDefaultVerbatim, errorCodes: dnsErrorCodes, + getDefaultResultOrder, setDefaultResultOrder, setDefaultResolver, } = require('internal/dns/utils'); @@ -335,6 +336,7 @@ module.exports = { lookup, lookupService, Resolver, + getDefaultResultOrder, setDefaultResultOrder, setServers: defaultResolverSetServers, diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 71545799a98bdb..fa8f0b8cf14103 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -284,6 +284,10 @@ function setDefaultResultOrder(value) { dnsOrder = value; } +function getDefaultResultOrder() { + return dnsOrder; +} + function createResolverClass(resolver) { const resolveMap = { __proto__: null }; @@ -346,6 +350,7 @@ module.exports = { validateTries, emitInvalidHostnameWarning, getDefaultVerbatim, + getDefaultResultOrder, setDefaultResultOrder, errorCodes, createResolverClass, From d4304e240bbe3235e71e5a335e2e1cac8da37fcd Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 6 Mar 2023 21:48:21 +0800 Subject: [PATCH 2/7] docs: update doc --- doc/api/dns.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/api/dns.md b/doc/api/dns.md index 59a56c7d1c2aa8..f22ae531001be8 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -792,6 +792,10 @@ 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()` + +Get the value of `dnsOrder`. + ## `dns.setServers(servers)` + Get the value of `dnsOrder`. ## `dns.setServers(servers)` @@ -1357,6 +1361,10 @@ default dns orders in workers. ### `dnsPromises.getDefaultResultOrder()` + + Get the value of `dnsOrder`. ### `dnsPromises.setServers(servers)` From 0c611c534dbc419ffdea00790c24f874d67e9382 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 7 Mar 2023 21:53:05 +0800 Subject: [PATCH 4/7] test: add test --- test/internet/test-dns-getDefaultResultOrder.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/internet/test-dns-getDefaultResultOrder.js diff --git a/test/internet/test-dns-getDefaultResultOrder.js b/test/internet/test-dns-getDefaultResultOrder.js new file mode 100644 index 00000000000000..a4d1a216a1261b --- /dev/null +++ b/test/internet/test-dns-getDefaultResultOrder.js @@ -0,0 +1,11 @@ +'use strict'; + +const assert = require('assert'); +const dns = require('dns'); + +dns.setDefaultResultOrder('ipv4first'); +dnsOrder = dns.getDefaultResultOrder(); +assert.ok(dnsOrder === 'ipv4first'); +dns.setDefaultResultOrder('verbatim'); +dnsOrder = dns.getDefaultResultOrder(); +assert.ok(dnsOrder === 'verbatim'); \ No newline at end of file From 6157c43076654a04d2a75eaaf815245f19ddc644 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 8 Mar 2023 08:21:29 +0800 Subject: [PATCH 5/7] test: update test --- test/internet/test-dns-getDefaultResultOrder.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/internet/test-dns-getDefaultResultOrder.js b/test/internet/test-dns-getDefaultResultOrder.js index a4d1a216a1261b..0ba17ec29e958d 100644 --- a/test/internet/test-dns-getDefaultResultOrder.js +++ b/test/internet/test-dns-getDefaultResultOrder.js @@ -1,11 +1,13 @@ 'use strict'; +const common = require('../common'); + const assert = require('assert'); const dns = require('dns'); dns.setDefaultResultOrder('ipv4first'); -dnsOrder = dns.getDefaultResultOrder(); +let dnsOrder = dns.getDefaultResultOrder(); assert.ok(dnsOrder === 'ipv4first'); dns.setDefaultResultOrder('verbatim'); dnsOrder = dns.getDefaultResultOrder(); -assert.ok(dnsOrder === 'verbatim'); \ No newline at end of file +assert.ok(dnsOrder === 'verbatim'); From e5343b540413dbeada16f5d96fe0afecf7a0b08f Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 8 Mar 2023 08:22:16 +0800 Subject: [PATCH 6/7] Update doc/api/dns.md Co-authored-by: Antoine du Hamel --- doc/api/dns.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/api/dns.md b/doc/api/dns.md index 3bce00a310d74f..2bb997bb0a2b4e 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -798,7 +798,11 @@ dns orders in workers. added: REPLACEME --> -Get the value of `dnsOrder`. +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)` From 7148776c0a0e36381ba5feedc2076cf4bdec9e3d Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 10 Mar 2023 07:48:47 +0800 Subject: [PATCH 7/7] test: update test --- test/internet/test-dns-getDefaultResultOrder.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/internet/test-dns-getDefaultResultOrder.js b/test/internet/test-dns-getDefaultResultOrder.js index 0ba17ec29e958d..ae176f1264508b 100644 --- a/test/internet/test-dns-getDefaultResultOrder.js +++ b/test/internet/test-dns-getDefaultResultOrder.js @@ -11,3 +11,14 @@ 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()); +}