diff --git a/index.js b/index.js index d58799b..7873569 100644 --- a/index.js +++ b/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, { diff --git a/test/updatetest.js b/test/updatetest.js index 29a4628..f8f7193 100644 --- a/test/updatetest.js +++ b/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));