Sha256: 7c6b5cd952a66b63645e0e6cb32a5392b3ac82e804054a5c468df1058ce6ffa7

Contents?: true

Size: 875 Bytes

Versions: 17

Compression:

Stored size: 875 Bytes

Contents

/*!
 * response-time
 * Copyright(c) 2011 TJ Holowaychuk
 * Copyright(c) 2014 Jonathan Ong
 * Copyright(c) 2014 Douglas Christopher Wilson
 * MIT Licensed
 */

/**
 * Module dependencies
 */

var onHeaders = require('on-headers')

/**
 * Reponse time:
 *
 * Adds the `X-Response-Time` header displaying the response
 * duration in milliseconds.
 *
 * @param {number} [digits=3]
 * @return {function}
 * @api public
 */

module.exports = function responseTime(digits) {
  digits = digits === undefined
    ? 3
    : digits

  return function responseTime(req, res, next) {
    var startAt = process.hrtime()

    onHeaders(res, function () {
      if (this.getHeader('X-Response-Time')) return;

      var diff = process.hrtime(startAt)
      var ms = diff[0] * 1e3 + diff[1] * 1e-6

      this.setHeader('X-Response-Time', ms.toFixed(digits) + 'ms')
    })

    next()
  }
}

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/response-time/index.js