diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 76291490e3..a9eee00191 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -906,7 +906,7 @@ class ClientRequest extends OutgoingMessage { // https://www.rfc-editor.org/rfc/rfc6266#section-4.3 // Refs: https://github.com/nodejs/node/pull/46528 if (isContentDispositionField(key) && this._contentLength) { - value = Buffer.from(value, "latin1"); + value = Buffer.from(value).toString("latin1"); } if (Array.isArray(value)) { diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 2043a00044..a599754b9f 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1559,3 +1559,30 @@ Deno.test("[node/http] req.url equals pathname + search", async () => { await promise; }); + +Deno.test("[node/http] ClientRequest content-disposition header works", async () => { + const payload = Buffer.from("hello world"); + let body = ""; + let headers = {} as http.IncomingHttpHeaders; + const { promise, resolve, reject } = Promise.withResolvers(); + const req = http.request("http://localhost:4545/echo_server", { + method: "PUT", + headers: { + "content-disposition": "attachment", + }, + }, (resp) => { + headers = resp.headers; + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + resolve(); + }); + }); + req.once("error", (e) => reject(e)); + req.end(payload); + await promise; + assertEquals(body, "hello world"); + assertEquals(headers["content-disposition"], "attachment"); +});