summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/http.ts
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-07-04 18:28:48 +0200
committerGitHub <noreply@github.com>2024-07-04 18:28:48 +0200
commit96b527b8df3c9e7e29c98a6a0d6876089b88bc09 (patch)
tree52337d1d3b597df97232c8c10262b1ef7fa56c8f /ext/node/polyfills/http.ts
parentf632b4a92e4e2c552cf31749792075bad0814c22 (diff)
fix(node/http): don't throw on .address() before .listen() (#24432)
It's perfectly valid to access `server.address()` before calling `.listen()`. Until a server actively listens on a socket Node will return `null` here, but we threw a "Cannot access property 'port' of undefined" instead. This was discovered when inspecting failures in Koa's test suite with Deno.
Diffstat (limited to 'ext/node/polyfills/http.ts')
-rw-r--r--ext/node/polyfills/http.ts3
1 files changed, 2 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,