summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/http.ts3
-rw-r--r--tests/unit_node/http_test.ts5
2 files changed, 7 insertions, 1 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index b1a536113..40155d998 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -1657,7 +1657,7 @@ export class ServerImpl extends EventEmitter {
#httpConnections: Set<Deno.HttpConn> = new Set();
#listener?: Deno.Listener;
- #addr: Deno.NetAddr;
+ #addr: Deno.NetAddr | null = null;
#hasClosed = false;
#server: Deno.HttpServer;
#unref = false;
@@ -1843,6 +1843,7 @@ export class ServerImpl extends EventEmitter {
}
address() {
+ if (this.#addr === null) return null;
return {
port: this.#addr.port,
address: this.#addr.hostname,
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts
index aeb92f129..0935aeac0 100644
--- a/tests/unit_node/http_test.ts
+++ b/tests/unit_node/http_test.ts
@@ -1251,3 +1251,8 @@ Deno.test("[node/http] http.request() post streaming body works", async () => {
clearTimeout(timeout);
assertEquals(server.listening, false);
});
+
+Deno.test("[node/http] Server.address() can be null", () => {
+ const server = http.createServer((_req, res) => res.end("it works"));
+ assertEquals(server.address(), null);
+});