mirror of
https://github.com/denoland/deno
synced 2024-08-27 12:00:17 +00:00
fix(ext/node): ServerResponse getHeader() return undefined (#21525)
Matches Node's return type.
Next.js check for `if (header === undefined)`:
e02fe314dc/packages/next/src/server/base-http/node.ts (L93)
This commit is contained in:
parent
e8fc7c20b7
commit
5e24e28318
|
@ -874,3 +874,24 @@ Deno.test("[node/http] node:http request.setHeader(header, null) doesn't throw",
|
|||
req.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("[node/http] ServerResponse getHeader", async () => {
|
||||
const { promise, resolve } = Promise.withResolvers<void>();
|
||||
const server = http.createServer((_req, res) => {
|
||||
res.setHeader("foo", "bar");
|
||||
assertEquals(res.getHeader("foo"), "bar");
|
||||
assertEquals(res.getHeader("ligma"), undefined);
|
||||
res.end("Hello World");
|
||||
});
|
||||
|
||||
server.listen(async () => {
|
||||
const { port } = server.address() as { port: number };
|
||||
const res = await fetch(`http://localhost:${port}`);
|
||||
assertEquals(await res.text(), "Hello World");
|
||||
server.close(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
await promise;
|
||||
});
|
||||
|
|
|
@ -1394,7 +1394,7 @@ export class ServerResponse extends NodeWritable {
|
|||
}
|
||||
|
||||
getHeader(name: string) {
|
||||
return this.#headers.get(name);
|
||||
return this.#headers.get(name) ?? undefined;
|
||||
}
|
||||
removeHeader(name: string) {
|
||||
return this.#headers.delete(name);
|
||||
|
|
Loading…
Reference in a new issue