/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; /* globals require, process, Buffer */ const http = require("http"); const html = `
`; const server = http.createServer((req, res) => { if (req.url === "/saveFile" && req.method.toLowerCase() === "post") { let totalSize = 0; req.on("data", chunk => { totalSize += chunk.length; }); req.on("end", () => { res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ status: "success", size: totalSize })); }); } else if ( req.url === "/downloadTest" && req.method.toLowerCase() === "get" ) { const contentLength = 32 * 1024 * 1024; // 32 MB res.writeHead(200, { "Content-Type": "application/octet-stream", "Content-Length": contentLength, "Content-Disposition": "attachment; filename=testfile.bin", "Cache-Control": "no-store, no-cache, must-revalidate", Pragma: "no-cache", }); const chunkSize = 1024 * 1024; // 1MB chunks for (let i = 0; i < contentLength / chunkSize; i++) { const chunk = Buffer.alloc(chunkSize, "0"); // Fill the chunk with zeros res.write(chunk); } res.end(); } else if (req.url === "/" && req.method.toLowerCase() === "get") { res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-store, no-cache, must-revalidate", Pragma: "no-cache", }); res.end(html); } else { res.writeHead(404, { "Content-Type": "text/plain" }); res.end("Not Found"); } }); server.listen(() => { console.log(`Server is running on http://localhost:${server.address().port}`); });