1'use strict'; 2 3const { 4 Symbol, 5 Date, 6 DatePrototypeGetMilliseconds, 7 DatePrototypeToUTCString, 8} = primordials; 9 10const { setUnrefTimeout } = require('internal/timers'); 11const { trace, isTraceCategoryEnabled } = internalBinding('trace_events'); 12const { 13 CHAR_LOWERCASE_B, 14 CHAR_LOWERCASE_E, 15} = require('internal/constants'); 16 17let utcCache; 18 19function utcDate() { 20 if (!utcCache) cache(); 21 return utcCache; 22} 23 24function cache() { 25 const d = new Date(); 26 utcCache = DatePrototypeToUTCString(d); 27 setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d)); 28} 29 30function resetCache() { 31 utcCache = undefined; 32} 33 34let traceEventId = 0; 35 36function getNextTraceEventId() { 37 return ++traceEventId; 38} 39 40function isTraceHTTPEnabled() { 41 return isTraceCategoryEnabled('node.http'); 42} 43 44const traceEventCategory = 'node,node.http'; 45 46function traceBegin(...args) { 47 trace(CHAR_LOWERCASE_B, traceEventCategory, ...args); 48} 49 50function traceEnd(...args) { 51 trace(CHAR_LOWERCASE_E, traceEventCategory, ...args); 52} 53 54module.exports = { 55 kOutHeaders: Symbol('kOutHeaders'), 56 kNeedDrain: Symbol('kNeedDrain'), 57 utcDate, 58 traceBegin, 59 traceEnd, 60 getNextTraceEventId, 61 isTraceHTTPEnabled, 62}; 63