2017-03-06 03:13:09 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-21 03:50:19 +01:00
|
|
|
const { setUnrefTimeout } = require('internal/timers');
|
2019-06-30 22:37:18 +02:00
|
|
|
const { PerformanceEntry, notify } = internalBinding('performance');
|
2016-10-17 20:38:52 +02:00
|
|
|
|
2018-08-23 16:46:07 +02:00
|
|
|
var nowCache;
|
|
|
|
var utcCache;
|
|
|
|
|
|
|
|
function nowDate() {
|
|
|
|
if (!nowCache) cache();
|
|
|
|
return nowCache;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:38:52 +02:00
|
|
|
function utcDate() {
|
2018-08-23 16:46:07 +02:00
|
|
|
if (!utcCache) cache();
|
|
|
|
return utcCache;
|
|
|
|
}
|
2017-12-21 03:50:19 +01:00
|
|
|
|
2018-08-23 16:46:07 +02:00
|
|
|
function cache() {
|
|
|
|
const d = new Date();
|
|
|
|
nowCache = d.valueOf();
|
|
|
|
utcCache = d.toUTCString();
|
|
|
|
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
|
2016-10-17 20:38:52 +02:00
|
|
|
}
|
2017-12-21 03:50:19 +01:00
|
|
|
|
|
|
|
function resetCache() {
|
2018-08-23 16:46:07 +02:00
|
|
|
nowCache = undefined;
|
|
|
|
utcCache = undefined;
|
2017-12-21 03:50:19 +01:00
|
|
|
}
|
2016-10-17 20:38:52 +02:00
|
|
|
|
2017-03-19 20:58:31 +01:00
|
|
|
function ondrain() {
|
|
|
|
if (this._httpMessage) this._httpMessage.emit('drain');
|
|
|
|
}
|
|
|
|
|
2019-06-30 22:37:18 +02:00
|
|
|
class HttpRequestTiming extends PerformanceEntry {
|
|
|
|
constructor(statistics) {
|
|
|
|
super();
|
|
|
|
this.name = 'HttpRequest';
|
|
|
|
this.entryType = 'http';
|
|
|
|
const startTime = statistics.startTime;
|
|
|
|
const diff = process.hrtime(startTime);
|
|
|
|
this.duration = diff[0] * 1000 + diff[1] / 1e6;
|
|
|
|
this.startTime = startTime[0] * 1000 + startTime[1] / 1e6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function emitStatistics(statistics) {
|
|
|
|
notify('http', new HttpRequestTiming(statistics));
|
|
|
|
}
|
|
|
|
|
2017-03-06 03:13:09 +01:00
|
|
|
module.exports = {
|
2017-03-19 20:58:31 +01:00
|
|
|
outHeadersKey: Symbol('outHeadersKey'),
|
|
|
|
ondrain,
|
2018-08-23 16:46:07 +02:00
|
|
|
nowDate,
|
2019-06-30 22:37:18 +02:00
|
|
|
utcDate,
|
|
|
|
emitStatistics
|
2017-03-06 03:13:09 +01:00
|
|
|
};
|