Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support dns-result-order Node.js cli flag
Co-authored-by: deepak1556 <hop2deep@gmail.com>
- Loading branch information
1 parent
f138d46
commit d107c7e
Showing
6 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: btea <2356281422@qq.com> | ||
Date: Wed, 26 Apr 2023 16:56:04 +0800 | ||
Subject: dns: expose getDefaultResultOrder | ||
|
||
PR-URL: https://github.com/nodejs/node/pull/46973 | ||
Fixes: https://github.com/nodejs/node/issues/46919 | ||
Reviewed-By: Matteo Collina <matteo.collina@gmail.com> | ||
Reviewed-By: Paolo Insogna <paolo@cowtech.it> | ||
|
||
diff --git a/doc/api/dns.md b/doc/api/dns.md | ||
index 59a56c7d1c2aa87b4786c5b6397978b195af1f83..2bb997bb0a2b4ebdbb9ae5625762e8c3184ace8d 100644 | ||
--- a/doc/api/dns.md | ||
+++ b/doc/api/dns.md | ||
@@ -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 | ||
@@ -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 | ||
diff --git a/lib/dns.js b/lib/dns.js | ||
index 0f66b184d48a511f162e5a97052ded864fb60b7e..dddc84c20389fe9fd86f2cd94f535adfd7935adc 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 78777752c999e256e71480650e04eb488555ef82..dcfa639f2d6b6217fa6002a3dd8f1f59754308e7 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 511d857b59191cf11c1d93f53886995538d940c4..2377e9ca5931f28ed3e623f123ec16d22d5ca06c 100644 | ||
--- a/lib/internal/dns/utils.js | ||
+++ b/lib/internal/dns/utils.js | ||
@@ -283,6 +283,10 @@ function setDefaultResultOrder(value) { | ||
dnsOrder = value; | ||
} | ||
|
||
+function getDefaultResultOrder() { | ||
+ return dnsOrder; | ||
+} | ||
+ | ||
function createResolverClass(resolver) { | ||
const resolveMap = ObjectCreate(null); | ||
|
||
@@ -345,6 +349,7 @@ module.exports = { | ||
validateTries, | ||
emitInvalidHostnameWarning, | ||
getDefaultVerbatim, | ||
+ getDefaultResultOrder, | ||
setDefaultResultOrder, | ||
errorCodes, | ||
createResolverClass, | ||
diff --git a/test/internet/test-dns-getDefaultResultOrder.js b/test/internet/test-dns-getDefaultResultOrder.js | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..ae176f1264508b847ae5dd18f2593d607b2f1a98 | ||
--- /dev/null | ||
+++ b/test/internet/test-dns-getDefaultResultOrder.js | ||
@@ -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()); | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const dns = require('node:dns'); | ||
console.log(dns.getDefaultResultOrder()); | ||
process.exit(0); |