summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/http.ts2
-rw-r--r--tests/unit_node/http_test.ts27
2 files changed, 28 insertions, 1 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 76291490e..a9eee0019 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 2043a0004..a599754b9 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<void>();
+ 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");
+});