3 * Connect - responseTime
4 * Copyright(c) 2011 TJ Holowaychuk
9 * Adds the `X-Response-Time` header displaying the response
10 * duration in milliseconds.
16 module.exports = function responseTime(){
17 return function(req, res, next){
18 var writeHead = res.writeHead
21 if (res._responseTime) return next();
22 res._responseTime = true;
24 // proxy writeHead to calculate duration
25 res.writeHead = function(status, headers){
26 var duration = new Date - start;
27 res.setHeader('X-Response-Time', duration + 'ms');
28 res.writeHead = writeHead;
29 res.writeHead(status, headers);