summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/http.ts5
-rw-r--r--tests/unit_node/http_test.ts4
2 files changed, 7 insertions, 2 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 933a8dbcd..67981e8de 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -1653,7 +1653,10 @@ export class ServerImpl extends EventEmitter {
// TODO(bnoordhuis) Node prefers [::] when host is omitted,
// we on the other hand default to 0.0.0.0.
- const hostname = options.host ?? "0.0.0.0";
+ let hostname = options.host ?? "0.0.0.0";
+ if (hostname == "localhost") {
+ hostname = "127.0.0.1";
+ }
this.#addr = {
hostname,
port,
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts
index 57ade6298..049cdbbbc 100644
--- a/tests/unit_node/http_test.ts
+++ b/tests/unit_node/http_test.ts
@@ -27,7 +27,9 @@ Deno.test("[node/http listen]", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
const server = http.createServer();
- server.listen(() => {
+ server.listen(42453, "localhost", () => {
+ // @ts-ignore address() is not a string
+ assertEquals(server.address()!.address, "127.0.0.1");
server.close();
});
server.on("close", () => {