diff options
author | James M Snell <jasnell@gmail.com> | 2016-10-17 21:38:52 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-08-04 22:55:22 +0300 |
commit | 9ea363ee99165011ddcb5d9c8d16b3a22f140bc9 (patch) | |
tree | b8acbde38a11a33994fb3441aebf7808480597d0 /lib/internal/http.js | |
parent | 1abfbbb1c479c550760b5f428eee5dbcc18243b3 (diff) |
http: move utcDate to internal/http.js
PR-URL: https://github.com/nodejs/node/pull/14239
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/internal/http.js')
-rwxr-xr-x[-rw-r--r--] | lib/internal/http.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/internal/http.js b/lib/internal/http.js index 0b12bc7c8fb..71e32498f35 100644..100755 --- 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 }; |