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