Skip to content

Commit

Permalink
Rename var
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Feb 10, 2020
1 parent 7160146 commit 1988c3f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}
Expand Down

0 comments on commit 1988c3f

Please sign in to comment.