diff --git a/src/utils/last-modified.js b/src/utils/last-modified.js index 3f3dde9d..299379f4 100644 --- a/src/utils/last-modified.js +++ b/src/utils/last-modified.js @@ -45,7 +45,11 @@ export function updateLastModified(state, res, httpDate) { * @return {string} the last modified date */ export function extractLastModified(headers) { - const lastModified = headers.get('x-amz-meta-x-source-last-modified'); + let lastModified = headers.get('x-amz-meta-x-source-last-modified'); + if (lastModified && lastModified !== 'null') { + return lastModified; + } + lastModified = headers.get('x-amz-meta-last-modified'); if (lastModified && lastModified !== 'null') { return lastModified; } diff --git a/test/utils/last-modified.test.js b/test/utils/last-modified.test.js index 3853fa26..9f4fb575 100644 --- a/test/utils/last-modified.test.js +++ b/test/utils/last-modified.test.js @@ -60,12 +60,49 @@ describe('Last Modified Utils Test', () => { assert.strictEqual(res.headers.get('last-modified'), 'Wed, 12 Jan 2022 09:33:01 GMT'); }); + it('uses meta source-last-modified', async () => { + /** @type PipelineResponse */ + const res = { + headers: new Map([ + ['last-modified', 'Wed, 12 Jan 2022 09:33:01 GMT'], + ['x-amz-meta-x-source-last-modified', 'Wed, 13 Jan 2022 09:33:01 GMT'], + ]), + }; + const date = extractLastModified(res.headers); + assert.strictEqual(date, 'Wed, 13 Jan 2022 09:33:01 GMT'); + }); + + it('uses meta last-modified', async () => { + /** @type PipelineResponse */ + const res = { + headers: new Map([ + ['last-modified', 'Wed, 12 Jan 2022 09:33:01 GMT'], + ['x-amz-meta-last-modified', 'Wed, 13 Jan 2022 09:33:01 GMT'], + ]), + }; + const date = extractLastModified(res.headers); + assert.strictEqual(date, 'Wed, 13 Jan 2022 09:33:01 GMT'); + }); + it('uses last-modified when meta source-last-modified is "null"', async () => { + /** @type PipelineResponse */ + const res = { + headers: new Map([ + ['last-modified', 'Wed, 12 Jan 2022 09:33:01 GMT'], + ['x-amz-meta-x-source-last-modified', 'Wed, 12 Jan 2022 09:33:01 GMT'], + ]), + }; + const date = extractLastModified(res.headers); + assert.strictEqual(date, 'Wed, 12 Jan 2022 09:33:01 GMT'); + }); + + it('uses last-modified when meta last-modified is "null"', async () => { /** @type PipelineResponse */ const res = { headers: new Map([ ['last-modified', 'Wed, 12 Jan 2022 09:33:01 GMT'], ['x-amz-meta-x-source-last-modified', 'null'], + ['x-amz-meta-last-modified', 'null'], ]), }; const date = extractLastModified(res.headers);