Skip to content

Commit 6f58fe2

Browse files
fix: added cache headers to file backend (#623)
1 parent f4ae982 commit 6f58fe2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/storage/backend/file.ts

+35
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,41 @@ export class FileBackend implements StorageBackendAdapter {
100100
const lastModified = new Date(0)
101101
lastModified.setUTCMilliseconds(data.mtimeMs)
102102

103+
if (headers?.ifNoneMatch && headers.ifNoneMatch === eTag) {
104+
return {
105+
metadata: {
106+
cacheControl: cacheControl || 'no-cache',
107+
mimetype: contentType || 'application/octet-stream',
108+
lastModified: lastModified,
109+
httpStatusCode: 304,
110+
size: data.size,
111+
eTag,
112+
contentLength: 0,
113+
},
114+
body: undefined,
115+
httpStatusCode: 304,
116+
}
117+
}
118+
119+
if (headers?.ifModifiedSince) {
120+
const ifModifiedSince = new Date(headers.ifModifiedSince)
121+
if (lastModified <= ifModifiedSince) {
122+
return {
123+
metadata: {
124+
cacheControl: cacheControl || 'no-cache',
125+
mimetype: contentType || 'application/octet-stream',
126+
lastModified: lastModified,
127+
httpStatusCode: 304,
128+
size: data.size,
129+
eTag,
130+
contentLength: 0,
131+
},
132+
body: undefined,
133+
httpStatusCode: 304,
134+
}
135+
}
136+
}
137+
103138
if (headers?.range) {
104139
const parts = headers.range.replace(/bytes=/, '').split('-')
105140
const startRange = parseInt(parts[0], 10)

0 commit comments

Comments
 (0)