1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(ext/node): don't concat set-cookie in ServerResponse.appendHeader (#25000)

Follow-on to
https://github.com/denoland/deno/pull/24216/files#r1642188672
This commit is contained in:
Luca Casonato 2024-08-12 12:01:37 +02:00 committed by GitHub
parent 004b74c8c6
commit 56e8ed5eb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -1439,12 +1439,11 @@ export class ServerResponse extends NodeWritable {
} }
appendHeader(name: string, value: string | string[]) { appendHeader(name: string, value: string | string[]) {
if (Array.isArray(value)) {
this.#hasNonStringHeaders = true;
}
if (this.#headers[name] === undefined) { if (this.#headers[name] === undefined) {
if (Array.isArray(value)) this.#hasNonStringHeaders = true;
this.#headers[name] = value; this.#headers[name] = value;
} else { } else {
this.#hasNonStringHeaders = true;
if (!Array.isArray(this.#headers[name])) { if (!Array.isArray(this.#headers[name])) {
this.#headers[name] = [this.#headers[name]]; this.#headers[name] = [this.#headers[name]];
} }

View file

@ -1118,6 +1118,27 @@ Deno.test("[node/http] ServerResponse appendHeader", async () => {
await promise; await promise;
}); });
Deno.test("[node/http] ServerResponse appendHeader set-cookie", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
const server = http.createServer((_req, res) => {
res.appendHeader("Set-Cookie", "a=b");
res.appendHeader("Set-Cookie", "c=d");
res.end("Hello World");
});
server.listen(async () => {
const { port } = server.address() as { port: number };
const res = await fetch(`http://localhost:${port}`);
assertEquals(res.headers.getSetCookie(), ["a=b", "c=d"]);
assertEquals(await res.text(), "Hello World");
server.close(() => {
resolve();
});
});
await promise;
});
Deno.test("[node/http] IncomingMessage override", () => { Deno.test("[node/http] IncomingMessage override", () => {
const req = new http.IncomingMessage(new net.Socket()); const req = new http.IncomingMessage(new net.Socket());
// https://github.com/dougmoscrop/serverless-http/blob/3aaa6d0fe241109a8752efb011c242d249f32368/lib/request.js#L20-L30 // https://github.com/dougmoscrop/serverless-http/blob/3aaa6d0fe241109a8752efb011c242d249f32368/lib/request.js#L20-L30