Created
July 11, 2010 09:52
-
-
Save johnl/471431 to your computer and use it in GitHub Desktop.
Script to test streaming of request body in nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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