Skip to content

Instantly share code, notes, and snippets.

@johnl
Created July 11, 2010 09:52
Show Gist options
  • Save johnl/471431 to your computer and use it in GitHub Desktop.
Save johnl/471431 to your computer and use it in GitHub Desktop.
Script to test streaming of request body in nodejs
// Script to test streaming of request body
// test with: curl --data-binary @somebigfile http://localhost:8124
//
var http = require('http');
http.createServer(function (req, res) {
console.log('New request');
var total = 0;
req.addListener('data', function (chunk) {
total += chunk.length;
console.log('Data chunk received ' + chunk.length / 1024 + 'k');
});
req.addListener('end', function () {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Thanks for the upload!\n');
console.log("End of request, received: " + total / 1024 + "k in total");
});
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment