A HTTP application is sending a large body in a specific POST method. I would like to measure the time taken in the server since the headers were received until the body was received. Is there a way I can assign events (data, end) to a route definition in restify or express? I wouldn't like to switch to node.js's raw HTTP server.
Asked
Active
Viewed 576 times
1 Answers
1
Restify uses formidable to process file uploads. You can use the bodyParser plugin bundled with restify to listen to events on the multipart file handler. The end
event can be logged to know when the file was completely received.
Use the restify server's pre() method to record when the request was received.
var restify = require('restify');
var server = restify.createServer();
server.post('/upload', function(req, res, next){
res.send({upload: 'done'});
next();
});
server.pre(function (req, res, next) {
console.log("Request received at: " + req._time);
next();
});
server.use(restify.bodyParser({
multipartFileHandler: function(part) {
// Fired when the parser is done receiving the file
part.on('end', function(data) {
console.log('File parsing ended: ' + new Date().getTime());
});
}
}));
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});

SarathMS
- 539
- 2
- 6