diff options
Diffstat (limited to 'deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-cache-semantics/node4/index.js')
-rw-r--r-- | deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-cache-semantics/node4/index.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-cache-semantics/node4/index.js b/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-cache-semantics/node4/index.js index 7011106818..bcdaebe80f 100644 --- a/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-cache-semantics/node4/index.js +++ b/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/http-cache-semantics/node4/index.js @@ -271,7 +271,14 @@ module.exports = function () { CachePolicy.prototype.responseHeaders = function responseHeaders() { var headers = this._copyWithoutHopByHopHeaders(this._resHeaders); - headers.age = '' + Math.round(this.age()); + var age = this.age(); + + // A cache SHOULD generate 113 warning if it heuristically chose a freshness + // lifetime greater than 24 hours and the response's age is greater than 24 hours. + if (age > 3600 * 24 && !this._hasExplicitExpiration() && this.maxAge() > 3600 * 24) { + headers.warning = (headers.warning ? `${headers.warning}, ` : '') + '113 - "rfc7234 5.5.4"'; + } + headers.age = `${Math.round(age)}`; return headers; }; @@ -314,6 +321,15 @@ module.exports = function () { return isFinite(ageValue) ? ageValue : 0; }; + /** + * Value of applicable max-age (or heuristic equivalent) in seconds. This counts since response's `Date`. + * + * For an up-to-date value, see `timeToLive()`. + * + * @return Number + */ + + CachePolicy.prototype.maxAge = function maxAge() { if (!this.storable() || this._rescc['no-cache']) { return 0; @@ -442,7 +458,7 @@ module.exports = function () { /* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */ if (this._resHeaders.etag) { - headers['if-none-match'] = headers['if-none-match'] ? headers['if-none-match'] + ', ' + this._resHeaders.etag : this._resHeaders.etag; + headers['if-none-match'] = headers['if-none-match'] ? `${headers['if-none-match']}, ${this._resHeaders.etag}` : this._resHeaders.etag; } // Clients MAY issue simple (non-subrange) GET requests with either weak validators or strong validators. Clients MUST NOT use weak validators in other forms of request. @@ -531,7 +547,7 @@ module.exports = function () { var newResponse = Object.assign({}, response, { status: this._status, method: this._method, - headers: headers + headers }); return { policy: new this.constructor(request, newResponse), |