Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b2749e

Browse filesBrowse files
bnoordhuistreysis
authored andcommitted
dns: default to verbatim=true in dns.lookup()
Switch the default from `ipv4first` to `verbatim` (return them exactly as the resolver sent them to us). PR-URL: #39987 Fixes: #31566 Refs: #6307 Refs: #20710 Refs: #38099 Co-authored-by: treysis <treysis@gmx.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent b6ac7e6 commit 1b2749e
Copy full SHA for 1b2749e
Expand file treeCollapse file tree

24 files changed

+70
-54
lines changed
Open diff view settings
Collapse file

‎doc/api/dns.md‎

Copy file name to clipboardExpand all lines: doc/api/dns.md
+5-3Lines changed: 5 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ section if a custom port is used.
170170
<!-- YAML
171171
added: v0.1.90
172172
changes:
173+
- version: REPLACEME
174+
pr-url: https://github.com/nodejs/node/pull/39987
175+
description: The `verbatim` options defaults to `true` now.
173176
- version: v8.5.0
174177
pr-url: https://github.com/nodejs/node/pull/14731
175178
description: The `verbatim` option is supported now.
@@ -190,10 +193,9 @@ changes:
190193
* `verbatim` {boolean} When `true`, the callback receives IPv4 and IPv6
191194
addresses in the order the DNS resolver returned them. When `false`,
192195
IPv4 addresses are placed before IPv6 addresses.
193-
**Default:** currently `false` (addresses are reordered) but this is
194-
expected to change in the not too distant future. Default value is
196+
**Default:** `true` (addresses are reordered). Default value is
195197
configurable using [`dns.setDefaultResultOrder()`][] or
196-
[`--dns-result-order`][]. New code should use `{ verbatim: true }`.
198+
[`--dns-result-order`][].
197199
* `callback` {Function}
198200
* `err` {Error}
199201
* `address` {string} A string representation of an IPv4 or IPv6 address.
Collapse file

‎lib/internal/dns/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/utils.js
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,10 @@ function emitInvalidHostnameWarning(hostname) {
193193
);
194194
}
195195

196-
let dnsOrder = getOptionValue('--dns-result-order') || 'ipv4first';
196+
let dnsOrder = getOptionValue('--dns-result-order') || 'verbatim';
197197

198198
function getDefaultVerbatim() {
199-
switch (dnsOrder) {
200-
case 'verbatim':
201-
return true;
202-
case 'ipv4first':
203-
default:
204-
return false;
205-
}
199+
return dnsOrder !== 'ipv4first';
206200
}
207201

208202
function setDefaultResultOrder(value) {
Collapse file

‎test/common/inspector-helper.js‎

Copy file name to clipboardExpand all lines: test/common/inspector-helper.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class NodeInstance extends EventEmitter {
392392
console.log('[test]', `Testing ${path}`);
393393
const headers = hostHeaderValue ? { 'Host': hostHeaderValue } : null;
394394
return this.portPromise.then((port) => new Promise((resolve, reject) => {
395-
const req = http.get({ host, port, path, headers }, (res) => {
395+
const req = http.get({ host, port, family: 4, path, headers }, (res) => {
396396
let response = '';
397397
res.setEncoding('utf8');
398398
res
@@ -418,6 +418,7 @@ class NodeInstance extends EventEmitter {
418418
const port = await this.portPromise;
419419
return http.get({
420420
port,
421+
family: 4,
421422
path: parseURL(devtoolsUrl).path,
422423
headers: {
423424
'Connection': 'Upgrade',
Collapse file

‎test/parallel/test-cluster-message.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-message.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if (cluster.isWorker) {
6060
maybeReply();
6161
});
6262

63-
server.listen(0, '127.0.0.1');
63+
server.listen(0);
6464
} else if (cluster.isPrimary) {
6565

6666
const checks = {
Collapse file

‎test/parallel/test-http-localaddress.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-localaddress.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const server = http.createServer((req, res) => {
4242
server.listen(0, '127.0.0.1', () => {
4343
const options = { host: 'localhost',
4444
port: server.address().port,
45+
family: 4,
4546
path: '/',
4647
method: 'GET',
4748
localAddress: '127.0.0.2' };
Collapse file

‎test/parallel/test-http-upgrade-client.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-upgrade-client.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const server = net.createServer(function(c) {
4949
});
5050
});
5151

52-
server.listen(0, '127.0.0.1', common.mustCall(function() {
52+
server.listen(0, common.mustCall(function() {
5353
const port = this.address().port;
5454
const headers = [
5555
{
Collapse file

‎test/parallel/test-http2-connect-options.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-connect-options.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const server = http2.createServer((req, res) => {
2222
});
2323

2424
server.listen(0, '127.0.0.1', common.mustCall(() => {
25-
const options = { localAddress: '127.0.0.2' };
25+
const options = { localAddress: '127.0.0.2', family: 4 };
2626

2727
const client = http2.connect(
2828
'http://localhost:' + server.address().port,
Collapse file

‎test/parallel/test-https-localaddress.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-https-localaddress.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ server.listen(0, '127.0.0.1', function() {
5252
const options = {
5353
host: 'localhost',
5454
port: this.address().port,
55+
family: 4,
5556
path: '/',
5657
method: 'GET',
5758
localAddress: '127.0.0.2',
Collapse file

‎test/parallel/test-net-connect-options-port.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-net-connect-options-port.js
+24-12Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const net = require('net');
8383
}
8484
}, expectedConnections));
8585

86-
server.listen(0, 'localhost', common.mustCall(() => {
86+
server.listen(0, common.localhostIPv4, common.mustCall(() => {
8787
const port = server.address().port;
8888

8989
// Total connections = 3 * 4(canConnect) * 6(doConnect) = 72
@@ -133,28 +133,35 @@ function doConnect(args, getCb) {
133133
}
134134

135135
function syncFailToConnect(port, assertErr, optOnly) {
136+
const family = 4;
136137
if (!optOnly) {
137138
// connect(port, cb) and connect(port)
138-
const portArgFunctions = doConnect([port], () => common.mustNotCall());
139+
const portArgFunctions = doConnect([{ port, family }],
140+
() => common.mustNotCall());
139141
for (const fn of portArgFunctions) {
140142
assert.throws(fn, assertErr, `${fn.name}(${port})`);
141143
}
142144

143145
// connect(port, host, cb) and connect(port, host)
144-
const portHostArgFunctions = doConnect([port, 'localhost'],
146+
const portHostArgFunctions = doConnect([{ port,
147+
host: 'localhost',
148+
family }],
145149
() => common.mustNotCall());
146150
for (const fn of portHostArgFunctions) {
147151
assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`);
148152
}
149153
}
150154
// connect({port}, cb) and connect({port})
151-
const portOptFunctions = doConnect([{ port }], () => common.mustNotCall());
155+
const portOptFunctions = doConnect([{ port, family }],
156+
() => common.mustNotCall());
152157
for (const fn of portOptFunctions) {
153158
assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`);
154159
}
155160

156161
// connect({port, host}, cb) and connect({port, host})
157-
const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }],
162+
const portHostOptFunctions = doConnect([{ port: port,
163+
host: 'localhost',
164+
family: family }],
158165
() => common.mustNotCall());
159166
for (const fn of portHostOptFunctions) {
160167
assert.throws(fn,
@@ -165,27 +172,30 @@ function syncFailToConnect(port, assertErr, optOnly) {
165172

166173
function canConnect(port) {
167174
const noop = () => common.mustCall();
175+
const family = 4;
168176

169177
// connect(port, cb) and connect(port)
170-
const portArgFunctions = doConnect([port], noop);
178+
const portArgFunctions = doConnect([{ port, family }], noop);
171179
for (const fn of portArgFunctions) {
172180
fn();
173181
}
174182

175183
// connect(port, host, cb) and connect(port, host)
176-
const portHostArgFunctions = doConnect([port, 'localhost'], noop);
184+
const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }],
185+
noop);
177186
for (const fn of portHostArgFunctions) {
178187
fn();
179188
}
180189

181190
// connect({port}, cb) and connect({port})
182-
const portOptFunctions = doConnect([{ port }], noop);
191+
const portOptFunctions = doConnect([{ port, family }], noop);
183192
for (const fn of portOptFunctions) {
184193
fn();
185194
}
186195

187196
// connect({port, host}, cb) and connect({port, host})
188-
const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop);
197+
const portHostOptFns = doConnect([{ port, host: 'localhost', family }],
198+
noop);
189199
for (const fn of portHostOptFns) {
190200
fn();
191201
}
@@ -198,20 +208,22 @@ function asyncFailToConnect(port) {
198208
});
199209

200210
const dont = () => common.mustNotCall();
211+
const family = 4;
201212
// connect(port, cb) and connect(port)
202-
const portArgFunctions = doConnect([port], dont);
213+
const portArgFunctions = doConnect([{ port, family }], dont);
203214
for (const fn of portArgFunctions) {
204215
fn().on('error', onError());
205216
}
206217

207218
// connect({port}, cb) and connect({port})
208-
const portOptFunctions = doConnect([{ port }], dont);
219+
const portOptFunctions = doConnect([{ port, family }], dont);
209220
for (const fn of portOptFunctions) {
210221
fn().on('error', onError());
211222
}
212223

213224
// connect({port, host}, cb) and connect({port, host})
214-
const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont);
225+
const portHostOptFns = doConnect([{ port, host: 'localhost', family }],
226+
dont);
215227
for (const fn of portHostOptFns) {
216228
fn().on('error', onError());
217229
}
Collapse file

‎test/parallel/test-net-dns-lookup.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-net-dns-lookup.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const server = net.createServer(function(client) {
2929
server.close();
3030
});
3131

32-
server.listen(0, '127.0.0.1', common.mustCall(function() {
32+
server.listen(0, common.mustCall(function() {
3333
net.connect(this.address().port, 'localhost')
3434
.on('lookup', common.mustCall(function(err, ip, type, host) {
3535
assert.strictEqual(err, null);
36-
assert.strictEqual(ip, '127.0.0.1');
37-
assert.strictEqual(type, 4);
36+
assert.match(ip, /^(127\.0\.0\.1|::1)$/);
37+
assert.match(type.toString(), /^(4|6)$/);
3838
assert.strictEqual(host, 'localhost');
3939
}));
4040
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.