Skip to content

Instantly share code, notes, and snippets.

@samsonjs
Created August 24, 2010 17:02
Show Gist options
  • Save samsonjs/547896 to your computer and use it in GitHub Desktop.
Save samsonjs/547896 to your computer and use it in GitHub Desktop.
var http = require('http'),
qs = require('querystring'),
url = require('url'),
sys = require('sys'),
handlePOST = function(request, callback){
var data = new Buffer(4096),
size = 0;
request.addListener('data', function(chunk){
chunk.copy(data, size, 0);
size += chunk.length;
});
request.addListener('end', function(){
callback(data, size);
});
};
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
if (request.method == 'POST'){
var t1 = new Date();
handlePOST(request, function(data, size){
var t2 = new Date()
sys.puts('Received ' + size + ' in ' + (t2-t1)
+ 'ms');
response.end('');
})
}
}).listen(8001, '0.0.0.0');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment