node/lib/internal/http.js
Robert Nagy e2f5bb7574 http: align with stream.Writable
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>
2021-03-10 15:04:00 +01:00

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
};