From 9ea363ee99165011ddcb5d9c8d16b3a22f140bc9 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 17 Oct 2016 11:38:52 -0700 Subject: [PATCH] http: move utcDate to internal/http.js PR-URL: https://github.com/nodejs/node/pull/14239 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina --- lib/_http_outgoing.js | 19 ++----------------- lib/internal/http.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 17 deletions(-) mode change 100644 => 100755 lib/_http_outgoing.js mode change 100644 => 100755 lib/internal/http.js diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js old mode 100644 new mode 100755 index 7a63406d51575b..f8ae30d4dee4f2 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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; @@ -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; @@ -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); diff --git a/lib/internal/http.js b/lib/internal/http.js old mode 100644 new mode 100755 index 0b12bc7c8fbe85..71e32498f359a1 --- a/lib/internal/http.js +++ b/lib/internal/http.js @@ -1,5 +1,21 @@ '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'); } @@ -7,4 +23,5 @@ function ondrain() { module.exports = { outHeadersKey: Symbol('outHeadersKey'), ondrain, + utcDate };