/usr/lib/nodejs/response-time/index.js is in node-response-time 2.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | /*!
* response-time
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies
*/
var deprecate = require('depd')('response-time')
var onHeaders = require('on-headers')
/**
* Reponse time:
*
* Adds the `X-Response-Time` header displaying the response
* duration in milliseconds.
*
* @param {object} [options]
* @param {number} [options.digits=3]
* @return {function}
* @api public
*/
module.exports = function responseTime(options) {
if (typeof options === 'number') {
// back-compat single number argument
deprecate('number argument: use {digits: ' + JSON.stringify(options) + '} instead')
options = { digits: options }
}
options = options || {}
// response time digits
var digits = options.digits !== undefined
? options.digits
: 3
// header name
var header = options.header || 'X-Response-Time'
// display suffix
var suffix = options.suffix !== undefined
? Boolean(options.suffix)
: true
return function responseTime(req, res, next) {
var startAt = process.hrtime()
onHeaders(res, function () {
if (this.getHeader(header)) {
return
}
var diff = process.hrtime(startAt)
var ms = diff[0] * 1e3 + diff[1] * 1e-6
var val = ms.toFixed(digits)
if (suffix) {
val += 'ms'
}
this.setHeader(header, val)
})
next()
}
}
|