Skip to content

Commit

Permalink
http: move utcDate to internal/http.js
Browse files Browse the repository at this point in the history
Backport-PR-URL: #14813
Backport-Reviewed-By: Anna Henningsen <anna@addaleax.net>
Backport-Reviewed-By: Timothy Gu <timothygu99@gmail.com>

PR-URL: #14239
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell authored and addaleax committed Aug 14, 2017
1 parent 9e51802 commit e0001dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lib/_http_outgoing.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

const assert = require('assert').ok;
const Stream = require('stream');
const timers = require('timers');
const util = require('util');
const internalUtil = require('internal/util');
const internalHttp = require('internal/http');
const Buffer = require('buffer').Buffer;
const common = require('_http_common');
const checkIsHttpToken = common._checkIsHttpToken;
Expand All @@ -36,6 +36,7 @@ const nextTick = require('internal/process/next_tick').nextTick;

const CRLF = common.CRLF;
const debug = common.debug;
const utcDate = internalHttp.utcDate;

var RE_FIELDS =
/^(?:Connection|Transfer-Encoding|Content-Length|Date|Expect|Trailer|Upgrade)$/i;
Expand Down Expand Up @@ -63,24 +64,8 @@ function isCookieField(s) {
return true;
}

var dateCache;
function utcDate() {
if (!dateCache) {
var d = new Date();
dateCache = d.toUTCString();
timers.enroll(utcDate, 1000 - d.getMilliseconds());
timers._unrefActive(utcDate);
}
return dateCache;
}
utcDate._onTimeout = function _onTimeout() {
dateCache = undefined;
};


function noopPendingOutput(amount) {}


function OutgoingMessage() {
Stream.call(this);

Expand Down
17 changes: 17 additions & 0 deletions lib/internal/http.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
'use strict';

const timers = require('timers');

var dateCache;
function utcDate() {
if (!dateCache) {
const d = new Date();
dateCache = d.toUTCString();
timers.enroll(utcDate, 1000 - d.getMilliseconds());
timers._unrefActive(utcDate);
}
return dateCache;
}
utcDate._onTimeout = function() {
dateCache = undefined;
};

function ondrain() {
if (this._httpMessage) this._httpMessage.emit('drain');
}

module.exports = {
outHeadersKey: Symbol('outHeadersKey'),
ondrain,
utcDate
};

0 comments on commit e0001dc

Please sign in to comment.