diff --git a/index.js b/index.js index 9577212..4992d91 100644 --- a/index.js +++ b/index.js @@ -342,12 +342,12 @@ module.exports = class CachePolicy { } _serverDate() { - const dateValue = Date.parse(this._resHeaders.date); - if (isFinite(dateValue)) { + const serverDate = Date.parse(this._resHeaders.date); + if (isFinite(serverDate)) { const maxClockDrift = 8 * 3600 * 1000; - const clockDrift = Math.abs(this._responseTime - dateValue); + const clockDrift = Math.abs(this._responseTime - serverDate); if (clockDrift < maxClockDrift) { - return dateValue; + return serverDate; } } return this._responseTime; @@ -419,22 +419,22 @@ module.exports = class CachePolicy { const defaultMinTtl = this._rescc.immutable ? this._immutableMinTtl : 0; - const dateValue = this._serverDate(); + const serverDate = this._serverDate(); if (this._resHeaders.expires) { const expires = Date.parse(this._resHeaders.expires); // A cache recipient MUST interpret invalid date formats, especially the value "0", as representing a time in the past (i.e., "already expired"). - if (Number.isNaN(expires) || expires < dateValue) { + if (Number.isNaN(expires) || expires < serverDate) { return 0; } - return Math.max(defaultMinTtl, (expires - dateValue) / 1000); + return Math.max(defaultMinTtl, (expires - serverDate) / 1000); } if (this._resHeaders['last-modified']) { const lastModified = Date.parse(this._resHeaders['last-modified']); - if (isFinite(lastModified) && dateValue > lastModified) { + if (isFinite(lastModified) && serverDate > lastModified) { return Math.max( defaultMinTtl, - ((dateValue - lastModified) / 1000) * this._cacheHeuristic + ((serverDate - lastModified) / 1000) * this._cacheHeuristic ); } }