Browse Source

Allow original non-updateable headers in revalidated response

master
Kornel 8 years ago
parent
commit
29655ce5fd
  1. 3
      index.js
  2. 7
      test/updatetest.js

3
index.js

@ -467,8 +467,7 @@ module.exports = class CachePolicy {
// of the corresponding header fields in the stored response.
const headers = {};
for(const k in this._resHeaders) {
if (excludedFromRevalidationUpdate[k]) continue;
headers[k] = k in response.headers ? response.headers[k] : this._resHeaders[k];
headers[k] = k in response.headers && !excludedFromRevalidationUpdate[k] ? response.headers[k] : this._resHeaders[k];
}
const newResponse = Object.assign({}, response, {

7
test/updatetest.js

@ -75,6 +75,13 @@ describe('Update revalidated', function() {
assert(!notModifiedResponseHeaders(simpleRequest, lastModifiedResponse, simpleRequest, cacheableResponse));
});
it('Skips update of content-length', function(){
const etaggedResponseWithLenght1 = withHeaders(etaggedResponse, {'content-length':1});
const etaggedResponseWithLenght2 = withHeaders(etaggedResponse, {'content-length':2});
const headers = notModifiedResponseHeaders(simpleRequest, etaggedResponseWithLenght1, simpleRequest, etaggedResponseWithLenght2);
assert.equal(1, headers['content-length']);
});
it('Ignored if validator is different', function(){
assert(!notModifiedResponseHeaders(simpleRequest, lastModifiedResponse, simpleRequest, etaggedResponse));
assert(!notModifiedResponseHeaders(simpleRequest, lastModifiedResponse, simpleRequest, weakTaggedResponse));

Loading…
Cancel
Save