Skip to content

Commit 9ce9e12

Browse files
committed
Date has to be up to date when the Age header is added
1 parent 3720df6 commit 9ce9e12

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const statusCodeCacheableByDefault = [200, 203, 204, 206, 300, 301, 404, 405, 41
55
// This implementation does not understand partial responses (206)
66
const understoodStatuses = [200, 203, 204, 300, 301, 302, 303, 307, 308, 404, 405, 410, 414, 501];
77

8-
const hopByHopHeaders = {'connection':true, 'keep-alive':true, 'proxy-authenticate':true, 'proxy-authorization':true, 'te':true, 'trailer':true, 'transfer-encoding':true, 'upgrade':true};
8+
const hopByHopHeaders = {
9+
'date': true, // included, because we add Age update Date
10+
'connection':true, 'keep-alive':true, 'proxy-authenticate':true, 'proxy-authorization':true, 'te':true, 'trailer':true, 'transfer-encoding':true, 'upgrade':true
11+
};
912
const excludedFromRevalidationUpdate = {
1013
// Since the old body is reused, it doesn't make sense to change properties of the body
1114
'content-length': true, 'content-encoding': true, 'transfer-encoding': true,
@@ -229,6 +232,7 @@ module.exports = class CachePolicy {
229232
headers.warning = (headers.warning ? `${headers.warning}, ` : '') + '113 - "rfc7234 5.5.4"';
230233
}
231234
headers.age = `${Math.round(age)}`;
235+
headers.date = new Date(this.now()).toUTCString();
232236
return headers;
233237
}
234238

test/responsetest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ describe('Response headers', function() {
372372
assert(!h.te);
373373
assert(!h.oompa);
374374
assert.equal(h['cache-control'], 'public, max-age=333');
375-
assert.equal(h.date, 'now', "date must stay the same for expires, age, etc");
375+
assert.notEqual(h.date, 'now', "updated age requires updated date");
376376
assert.equal(h.custom, 'header');
377377
assert.equal(h.age, '11');
378378
assert.equal(res.headers.age, '10');

0 commit comments

Comments
 (0)