summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/http.ts
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2024-10-16 20:58:44 +0900
committerGitHub <noreply@github.com>2024-10-16 20:58:44 +0900
commitd59599fc187c559ee231882773e1c5a2b932fc3d (patch)
tree3719d26bee7ce395afd28e4ab631dc5e63021327 /ext/node/polyfills/http.ts
parentea9c3ffaa240fc968832871000832eda1b92934a (diff)
fix(ext/node): fix dns.lookup result ordering (#26264)
partially unblocks #25470 This PR aligns the resolution of `localhost` hostname to Node.js behavior. In Node.js `dns.lookup("localhost", (_, addr) => console.log(addr))` prints ipv6 address `::1`, but it prints ipv4 address `127.0.0.1` in Deno. That difference causes some errors in the work of enabling `createConnection` option in `http.request` (#25470). This PR fixes the issue by aligning `dns.lookup` behavior to Node.js. This PR also changes the following behaviors (resolving TODOs): - `http.createServer` now listens on ipv6 address `[::]` by default on linux/mac - `net.createServer` now listens on ipv6 address `[::]` by default on linux/mac These changes are also alignments to Node.js behaviors.
Diffstat (limited to 'ext/node/polyfills/http.ts')
-rw-r--r--ext/node/polyfills/http.ts6
1 files changed, 3 insertions, 3 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index f3f6f86ed..349caeea6 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -50,6 +50,7 @@ import { urlToHttpOptions } from "ext:deno_node/internal/url.ts";
import { kEmptyObject } from "ext:deno_node/internal/util.mjs";
import { constants, TCP } from "ext:deno_node/internal_binding/tcp_wrap.ts";
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
+import { isWindows } from "ext:deno_node/_util/os.ts";
import {
connResetException,
ERR_HTTP_HEADERS_SENT,
@@ -1586,9 +1587,8 @@ export class ServerImpl extends EventEmitter {
port = options.port | 0;
}
- // TODO(bnoordhuis) Node prefers [::] when host is omitted,
- // we on the other hand default to 0.0.0.0.
- let hostname = options.host ?? "0.0.0.0";
+ // Use 0.0.0.0 for Windows, and [::] for other platforms.
+ let hostname = options.host ?? (isWindows ? "0.0.0.0" : "[::]");
if (hostname == "localhost") {
hostname = "127.0.0.1";
}