Browse Source

Default expirey should be Date header, not current date

pull/8/head
Luke Childs 8 years ago
parent
commit
6a27c731ae
  1. 8
      src/index.js

8
src/index.js

@ -14,13 +14,11 @@ expired.on = headers => {
// Parse headers if we got a raw string // Parse headers if we got a raw string
headers = (typeof headers === 'string') ? parse(headers) : headers; headers = (typeof headers === 'string') ? parse(headers) : headers;
let expiredOn = new Date(); // Default to Date header
let expiredOn = new Date(headers.date);
// Prefer Cache-Control // Prefer Cache-Control
if (headers['cache-control']) { if (headers['cache-control']) {
// Date from headers
const originDate = new Date(headers.date);
// Get max age ms // Get max age ms
let maxAge = headers['cache-control'].match(/max-age=(\d+)/); let maxAge = headers['cache-control'].match(/max-age=(\d+)/);
maxAge = parseInt(maxAge ? maxAge[1] : 0, 10); maxAge = parseInt(maxAge ? maxAge[1] : 0, 10);
@ -31,7 +29,7 @@ expired.on = headers => {
} }
// Calculate expirey date // Calculate expirey date
expiredOn = addSeconds(originDate, maxAge); expiredOn = addSeconds(expiredOn, maxAge);
// Fall back to Expires if it exists // Fall back to Expires if it exists
} else if (headers.expires) { } else if (headers.expires) {

Loading…
Cancel
Save