From 3a74fa60ca948b0bc1608ae0ad6e00236ccc846a Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 8 Dec 2023 17:43:19 +0900 Subject: [PATCH] fix(ext/node): allow null value for req.setHeader (#21391) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk --- cli/tests/unit_node/http_test.ts | 19 +++++++++++++++++++ ext/node/polyfills/_http_outgoing.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index b2b8eda0f6..ae708c3437 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -835,3 +835,22 @@ Deno.test("[node/https] node:https exports globalAgent", async () => { "node:https must export 'globalAgent' on module default export", ); }); + +Deno.test("[node/http] node:http request.setHeader(header, null) doesn't throw", () => { + { + const req = http.request("http://localhost:4545/"); + req.on("error", () => {}); + // @ts-expect-error - null is not a valid header value + req.setHeader("foo", null); + req.end(); + req.destroy(); + } + { + const req = https.request("https://localhost:4545/"); + req.on("error", () => {}); + // @ts-expect-error - null is not a valid header value + req.setHeader("foo", null); + req.end(); + req.destroy(); + } +}); diff --git a/ext/node/polyfills/_http_outgoing.ts b/ext/node/polyfills/_http_outgoing.ts index 8882ade552..1feb3e746e 100644 --- a/ext/node/polyfills/_http_outgoing.ts +++ b/ext/node/polyfills/_http_outgoing.ts @@ -249,7 +249,7 @@ export class OutgoingMessage extends Stream { } name = name.toString(); - headers[name.toLowerCase()] = [name, value.toString()]; + headers[name.toLowerCase()] = [name, String(value)]; return this; }