mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:13:21 +00:00

Futher aligns OutgoingMessage with stream.Writable. In particular re-uses the construct/destroy logic from streams. Due to a lot of subtle assumptions this PR unfortunately touches a lot of different parts. PR-URL: https://github.com/nodejs/node/pull/36816 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
50 lines
1003 B
JavaScript
50 lines
1003 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
Symbol,
|
|
Date,
|
|
DatePrototypeGetMilliseconds,
|
|
DatePrototypeToUTCString,
|
|
} = primordials;
|
|
|
|
const { setUnrefTimeout } = require('internal/timers');
|
|
|
|
const { InternalPerformanceEntry } = require('internal/perf/perf');
|
|
const { enqueue } = require('internal/perf/observe');
|
|
|
|
let utcCache;
|
|
|
|
function utcDate() {
|
|
if (!utcCache) cache();
|
|
return utcCache;
|
|
}
|
|
|
|
function cache() {
|
|
const d = new Date();
|
|
utcCache = DatePrototypeToUTCString(d);
|
|
setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d));
|
|
}
|
|
|
|
function resetCache() {
|
|
utcCache = undefined;
|
|
}
|
|
|
|
function emitStatistics(statistics) {
|
|
const startTime = statistics.startTime;
|
|
const diff = process.hrtime(startTime);
|
|
const entry = new InternalPerformanceEntry(
|
|
'HttpRequest',
|
|
'http',
|
|
startTime[0] * 1000 + startTime[1] / 1e6,
|
|
diff[0] * 1000 + diff[1] / 1e6,
|
|
undefined,
|
|
);
|
|
enqueue(entry);
|
|
}
|
|
|
|
module.exports = {
|
|
kOutHeaders: Symbol('kOutHeaders'),
|
|
utcDate,
|
|
emitStatistics
|
|
};
|