Skip to content

Commit 2b3454b

Browse files
authored
feat: return last modified for source based on timestamp (#142)
1 parent 2b76a00 commit 2b3454b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/utils/daResp.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ 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());
34+
}
35+
3236
if (ctx?.aclCtx && status < 500) {
3337
headers.append('X-da-actions', `/${ctx.key}=${[...ctx.aclCtx.actionSet]}`);
3438

test/utils/daResp.test.js

Lines changed: 2 additions & 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' };
22+
const metadata = { id: '1234', timestamp: '1719235200000' };
2323

2424
const resp = daResp({status: 200, body, contentType: 'text/plain', contentLength: 777, metadata}, ctx);
2525
assert.strictEqual(body, await resp.text());
@@ -32,6 +32,7 @@ describe('DA Resp', () => {
3232
assert.strictEqual('777', resp.headers.get('Content-Length'));
3333
assert.strictEqual('/foo/bar.html=read,write', resp.headers.get('X-da-actions'));
3434
assert.strictEqual('1234', resp.headers.get('X-da-id'));
35+
assert.strictEqual('Mon, 24 Jun 2024 13:20:00 GMT', resp.headers.get('Last-Modified'));
3536
assert(resp.headers.get('X-da-acltrace') === null);
3637
});
3738

0 commit comments

Comments
 (0)