Sha256: 94ecbff2b66fa9fcc12239809a5e648ccbad30ecfbd884ba114d8235e20bce3f

Contents?: true

Size: 725 Bytes

Versions: 28

Compression:

Stored size: 725 Bytes

Contents

/*!
 * Connect - responseTime
 * Copyright(c) 2011 TJ Holowaychuk
 * MIT Licensed
 */

/**
 * Adds the `X-Response-Time` header displaying the response
 * duration in milliseconds.
 *
 * @return {Function}
 * @api public
 */

module.exports = function responseTime(){
  return function(req, res, next){
    var writeHead = res.writeHead
      , start = new Date;

    if (res._responseTime) return next();
    res._responseTime = true;

    // proxy writeHead to calculate duration
    res.writeHead = function(status, headers){
      var duration = new Date - start;
      res.setHeader('X-Response-Time', duration + 'ms');
      res.writeHead = writeHead;
      res.writeHead(status, headers);
    };

    next();
  };
};

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
blackboard-3.1.9 lib/site_template/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.8.2 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.8.1 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.8.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.7.2 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.7.1 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.7.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.6.1 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.6.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.5.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.4.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.3.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.2.5 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.2.4 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.2.3 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.2.2 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.2.1 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.2.0 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.1.6 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js
vulcan-0.1.5 server/node_modules/express/node_modules/connect/lib/middleware/responseTime.js