Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect x-amz-meta-last-modified #627

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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