2017-03-06 02:13:09 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-30 15:55:29 +00:00
|
|
|
const {
|
2020-09-29 18:29:40 +00:00
|
|
|
Date,
|
2024-04-21 16:53:08 +00:00
|
|
|
Symbol,
|
2019-11-30 15:55:29 +00:00
|
|
|
} = primordials;
|
|
|
|
|
2017-12-21 02:50:19 +00:00
|
|
|
const { setUnrefTimeout } = require('internal/timers');
|
2024-07-16 18:40:22 +00:00
|
|
|
const { getCategoryEnabledBuffer, trace } = internalBinding('trace_events');
|
2022-08-05 14:25:06 +00:00
|
|
|
const {
|
|
|
|
CHAR_LOWERCASE_B,
|
|
|
|
CHAR_LOWERCASE_E,
|
|
|
|
} = require('internal/constants');
|
2021-01-29 00:34:27 +00:00
|
|
|
|
2019-11-12 15:46:28 +00:00
|
|
|
let utcCache;
|
2018-08-23 14:46:07 +00:00
|
|
|
|
2016-10-17 18:38:52 +00:00
|
|
|
function utcDate() {
|
2018-08-23 14:46:07 +00:00
|
|
|
if (!utcCache) cache();
|
|
|
|
return utcCache;
|
|
|
|
}
|
2017-12-21 02:50:19 +00:00
|
|
|
|
2018-08-23 14:46:07 +00:00
|
|
|
function cache() {
|
|
|
|
const d = new Date();
|
2024-07-06 08:33:16 +00:00
|
|
|
utcCache = d.toUTCString();
|
|
|
|
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
|
2016-10-17 18:38:52 +00:00
|
|
|
}
|
2017-12-21 02:50:19 +00:00
|
|
|
|
|
|
|
function resetCache() {
|
2018-08-23 14:46:07 +00:00
|
|
|
utcCache = undefined;
|
2017-12-21 02:50:19 +00:00
|
|
|
}
|
2016-10-17 18:38:52 +00:00
|
|
|
|
2022-08-05 14:25:06 +00:00
|
|
|
let traceEventId = 0;
|
|
|
|
|
|
|
|
function getNextTraceEventId() {
|
|
|
|
return ++traceEventId;
|
|
|
|
}
|
|
|
|
|
2024-07-16 18:40:22 +00:00
|
|
|
const httpEnabled = getCategoryEnabledBuffer('node.http');
|
|
|
|
|
2022-08-05 14:25:06 +00:00
|
|
|
function isTraceHTTPEnabled() {
|
2024-07-16 18:40:22 +00:00
|
|
|
return httpEnabled[0] > 0;
|
2022-08-05 14:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const traceEventCategory = 'node,node.http';
|
|
|
|
|
|
|
|
function traceBegin(...args) {
|
|
|
|
trace(CHAR_LOWERCASE_B, traceEventCategory, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
function traceEnd(...args) {
|
|
|
|
trace(CHAR_LOWERCASE_E, traceEventCategory, ...args);
|
|
|
|
}
|
|
|
|
|
2017-03-06 02:13:09 +00:00
|
|
|
module.exports = {
|
2019-08-12 06:52:18 +00:00
|
|
|
kOutHeaders: Symbol('kOutHeaders'),
|
2021-03-29 09:20:57 +00:00
|
|
|
kNeedDrain: Symbol('kNeedDrain'),
|
2019-06-30 20:37:18 +00:00
|
|
|
utcDate,
|
2022-08-05 14:25:06 +00:00
|
|
|
traceBegin,
|
|
|
|
traceEnd,
|
|
|
|
getNextTraceEventId,
|
|
|
|
isTraceHTTPEnabled,
|
2017-03-06 02:13:09 +00:00
|
|
|
};
|