aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/js/node/http/node-http.test.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts
index 0e7b3ca13..e8fe4dae8 100644
--- a/test/js/node/http/node-http.test.ts
+++ b/test/js/node/http/node-http.test.ts
@@ -169,6 +169,18 @@ describe("node:http", () => {
res.end("Hello World");
return;
}
+ if (reqUrl.pathname === "/uploadFile") {
+ let requestData = Buffer.alloc(0);
+ req.on("data", chunk => {
+ requestData = Buffer.concat([requestData, chunk]);
+ });
+ req.on("end", () => {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.write(requestData);
+ res.end();
+ });
+ return;
+ }
}
res.writeHead(200, { "Content-Type": "text/plain" });
@@ -540,6 +552,49 @@ describe("node:http", () => {
req.end();
});
});
+ it("uploading file by 'formdata/multipart', issue#3116", done => {
+ runTest(done, (server, serverPort, done) => {
+ const boundary = "----FormBoundary" + Date.now();
+
+ const formDataBegin = `--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="myfile.txt"\r\nContent-Type: application/octet-stream\r\n\r\n`;
+ const fileData = Buffer.from("80818283", "hex");
+ const formDataEnd = `\r\n--${boundary}--`;
+
+ const requestOptions = {
+ hostname: "localhost",
+ port: serverPort,
+ path: "/uploadFile",
+ method: "POST",
+ headers: {
+ "Content-Type": `multipart/form-data; boundary=${boundary}`,
+ },
+ };
+
+ const req = request(requestOptions, res => {
+ let responseData = Buffer.alloc(0);
+ res.on("data", chunk => {
+ responseData = Buffer.concat([responseData, chunk]);
+ });
+ res.on("end", () => {
+ try {
+ expect(responseData).toEqual(
+ Buffer.concat([Buffer.from(formDataBegin), fileData, Buffer.from(formDataEnd)]),
+ );
+ } catch (e) {
+ return done(e);
+ }
+ done();
+ });
+ });
+ req.on("error", err => {
+ done(err);
+ });
+ req.write(formDataBegin); // string
+ req.write(fileData); // Buffer
+ req.write(formDataEnd); // string
+ req.end();
+ });
+ });
});
describe("signal", () => {