nstdlib-nightly
Version:
Node.js standard library converted to runtime-agnostic ES modules.
61 lines (47 loc) • 1.35 kB
JavaScript
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/http.js
import { setUnrefTimeout } from "nstdlib/lib/internal/timers";
import {
getCategoryEnabledBuffer,
trace,
} from "nstdlib/stub/binding/trace_events";
import {
CHAR_LOWERCASE_B,
CHAR_LOWERCASE_E,
} from "nstdlib/lib/internal/constants";
let utcCache;
function utcDate() {
if (!utcCache) cache();
return utcCache;
}
function cache() {
const d = new Date();
utcCache = d.toUTCString();
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
}
function resetCache() {
utcCache = undefined;
}
let traceEventId = 0;
function getNextTraceEventId() {
return ++traceEventId;
}
const httpEnabled = getCategoryEnabledBuffer("node.http");
function isTraceHTTPEnabled() {
return httpEnabled[0] > 0;
}
const traceEventCategory = "node,node.http";
function traceBegin(...args) {
trace(CHAR_LOWERCASE_B, traceEventCategory, ...args);
}
function traceEnd(...args) {
trace(CHAR_LOWERCASE_E, traceEventCategory, ...args);
}
const _export_kOutHeaders_ = Symbol("kOutHeaders");
export { _export_kOutHeaders_ as kOutHeaders };
const _export_kNeedDrain_ = Symbol("kNeedDrain");
export { _export_kNeedDrain_ as kNeedDrain };
export { utcDate };
export { traceBegin };
export { traceEnd };
export { getNextTraceEventId };
export { isTraceHTTPEnabled };