Skip to content

Instantly share code, notes, and snippets.

@BenHall
Created April 18, 2013 21:37
Show Gist options
  • Save BenHall/5416437 to your computer and use it in GitHub Desktop.
Save BenHall/5416437 to your computer and use it in GitHub Desktop.
Return the response time as a HTTP header in NodeJS
var time = require('./response-time');
app.configure(function(){
app.use(time());
});
/*!
* Connect - responseTime
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
module.exports = function responseTime(){
return function(req, res, next){
var start = new Date();
if (res._responseTime) return next();
res._responseTime = true;
res.on('header', function(){
var duration = new Date() - start;
res.setHeader('X-Response-Time', duration + 'ms');
});
next();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment