Skip to content

Commit

Permalink
fix: respect x-amz-meta-last-modified (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
tripodsan committed Jun 19, 2024
1 parent 4508dae commit 1d3bce8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/last-modified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
37 changes: 37 additions & 0 deletions test/utils/last-modified.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d3bce8

Please sign in to comment.