Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node/http): don't throw on .address() before .listen() #24432

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/node/polyfills/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_node/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});