Skip to content

Commit

Permalink
http: move utcDate to internal/http.js
Browse files Browse the repository at this point in the history
PR-URL: #14239
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
jasnell committed Aug 4, 2017
1 parent 1abfbbb commit 9ea363e
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 @@ -37,6 +37,7 @@ const errors = require('internal/errors');

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 @@ -64,24 +65,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 9ea363e

Please sign in to comment.