From 6a27c731ae2e92662b6e0cb238edf86041c0fb75 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jan 2017 19:48:48 +0700 Subject: [PATCH] Default expirey should be Date header, not current date --- src/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 5c8d07a..7d71253 100644 --- a/src/index.js +++ b/src/index.js @@ -14,13 +14,11 @@ expired.on = headers => { // Parse headers if we got a raw string headers = (typeof headers === 'string') ? parse(headers) : headers; - let expiredOn = new Date(); + // Default to Date header + let expiredOn = new Date(headers.date); // Prefer Cache-Control if (headers['cache-control']) { - // Date from headers - const originDate = new Date(headers.date); - // Get max age ms let maxAge = headers['cache-control'].match(/max-age=(\d+)/); maxAge = parseInt(maxAge ? maxAge[1] : 0, 10); @@ -31,7 +29,7 @@ expired.on = headers => { } // Calculate expirey date - expiredOn = addSeconds(originDate, maxAge); + expiredOn = addSeconds(expiredOn, maxAge); // Fall back to Expires if it exists } else if (headers.expires) {