Skip to content

Instantly share code, notes, and snippets.

@Dador
Last active August 26, 2023 05:48
Show Gist options
  • Save Dador/746e9b7806f2d3b0f4e7d6913950fc00 to your computer and use it in GitHub Desktop.
Save Dador/746e9b7806f2d3b0f4e7d6913950fc00 to your computer and use it in GitHub Desktop.
head -c 10000 /dev/urandom | curl 'http://127.0.0.1:9090/' -X POST --data-binary @-
node test-server.js
const http = require("http");
const port = 9090;
const httpServer = http.createServer((req, res) => {
console.log("on req");
req.on("error", (err) => {
console.error("Error in req.on error", err);
res.writeHead(400);
res.end("Read error");
});
req.on("data", (chunk) => {
try {
console.log("on data", chunk.length);
} catch (e) {
console.error("Error in req.on data", e);
}
});
req.on("end", () => {
console.log("on end");
res.writeHead(200);
res.end("Ok");
});
});
httpServer.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment