Skip to content

Commit edf1de1

Browse files
authored
fix: last modified header for source (#145)
1 parent a384662 commit edf1de1

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/storage/object/get.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default async function getObject(env, { org, key }, head = false) {
3636
status: resp.$metadata.httpStatusCode,
3737
contentType: resp.ContentType,
3838
contentLength: resp.ContentLength,
39-
metadata: resp.Metadata,
39+
metadata: {
40+
...resp.Metadata,
41+
LastModified: resp.LastModified,
42+
},
4043
etag: resp.ETag,
4144
};
4245
} catch (e) {
@@ -56,7 +59,10 @@ export default async function getObject(env, { org, key }, head = false) {
5659
status: resp.status,
5760
contentType: resp.headers.get('content-type'),
5861
contentLength: resp.headers.get('content-length'),
59-
metadata: Metadata,
62+
metadata: {
63+
...resp.Metadata,
64+
LastModified: resp.headers.get('last-modified'),
65+
},
6066
etag: resp.headers.get('etag'),
6167
};
6268
}

src/utils/daResp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export default function daResp({
2929
headers.append('X-da-id', metadata.id);
3030
}
3131

32-
if (metadata?.timestamp) {
33-
headers.append('Last-Modified', new Date(parseInt(metadata.timestamp, 10)).toUTCString());
32+
if (metadata?.LastModified) {
33+
headers.append('Last-Modified', new Date(metadata.LastModified).toUTCString());
3434
}
3535

3636
if (ctx?.aclCtx && status < 500) {

test/utils/daResp.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('DA Resp', () => {
1919
const aclCtx = { actionSet: ['read', 'write'], pathLookup: new Map() };
2020
const ctx = { key: 'foo/bar.html', aclCtx };
2121
const body = 'foobar';
22-
const metadata = { id: '1234', timestamp: '1719235200000' };
22+
const metadata = { id: '1234', LastModified: '2024-06-24T13:20:00.000Z' };
2323

2424
const resp = daResp({status: 200, body, contentType: 'text/plain', contentLength: 777, metadata}, ctx);
2525
assert.strictEqual(body, await resp.text());

0 commit comments

Comments
 (0)