From 563da182857a841310f8aed47e2c40d462d14141 Mon Sep 17 00:00:00 2001 From: Ouyang Yadong Date: Tue, 6 Apr 2021 16:09:11 +0800 Subject: [PATCH] dns: allow --dns-order to change default dns verbatim Allow the "--dns-order" option to change the default value of verbatim in `dns.lookup()`. This is useful when running Node.js in ipv6-only environments to avoid possible ENETUNREACH errors. --- doc/api/cli.md | 13 ++++ doc/api/dns.md | 15 +++++ lib/dns.js | 19 +++++- lib/internal/dns/promises.js | 8 ++- lib/internal/dns/utils.js | 27 +++++++++ src/node_options.cc | 7 +++ src/node_options.h | 1 + .../test-dns-default-verbatim-false.js | 51 ++++++++++++++++ .../test-dns-default-verbatim-true.js | 51 ++++++++++++++++ test/parallel/test-dns-verbatim.js | 59 +++++++++++++++++++ 10 files changed, 246 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-dns-default-verbatim-false.js create mode 100644 test/parallel/test-dns-default-verbatim-true.js create mode 100644 test/parallel/test-dns-verbatim.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 055eac22f6f0a2..4c4e16b67706a9 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -181,6 +181,17 @@ Make built-in language features like `eval` and `new Function` that generate code from strings throw an exception instead. This does not affect the Node.js `vm` module. +### `--dns-order=value` + + +Set the default value of `verbatim` in [`dns.lookup()`][]. The value could be: +* `ipv4`: Set default `verbatim` `false`. +* `verbatim`: Set default `verbatim` `true`. + +Otherwise, default `verbatim` will be decided by Node.js. + ### `--enable-fips` + +* {boolean} + +By default set to `false`. Determines the default value of `verbatim` when +it's not passed to [`dns.lookup()`][] or [`dnsPromises.lookup()`][]. + +Configurable using the [`--dns-order`][] CLI option. Change `dns.verbatim` +will override the [`--dns-order`][] option. + ## DNS promises API