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

fix(ext/node): pass content-disposition header as string instead of bytes (#25128)

Closes https://github.com/denoland/deno/issues/25117
This commit is contained in:
Satya Rohith 2024-08-21 15:43:17 +05:30 committed by GitHub
parent dd8a9c509f
commit e920835417
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -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)) {

View file

@ -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");
});