• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const {
4  Symbol,
5  Date,
6} = primordials;
7
8const { setUnrefTimeout } = require('internal/timers');
9const { PerformanceEntry, notify } = internalBinding('performance');
10
11let utcCache;
12
13function utcDate() {
14  if (!utcCache) cache();
15  return utcCache;
16}
17
18function cache() {
19  const d = new Date();
20  utcCache = d.toUTCString();
21  setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
22}
23
24function resetCache() {
25  utcCache = undefined;
26}
27
28class HttpRequestTiming extends PerformanceEntry {
29  constructor(statistics) {
30    super();
31    this.name = 'HttpRequest';
32    this.entryType = 'http';
33    const startTime = statistics.startTime;
34    const diff = process.hrtime(startTime);
35    this.duration = diff[0] * 1000 + diff[1] / 1e6;
36    this.startTime = startTime[0] * 1000 + startTime[1] / 1e6;
37  }
38}
39
40function emitStatistics(statistics) {
41  notify('http', new HttpRequestTiming(statistics));
42}
43
44module.exports = {
45  kOutHeaders: Symbol('kOutHeaders'),
46  kNeedDrain: Symbol('kNeedDrain'),
47  utcDate,
48  emitStatistics
49};
50