Add no-store cache header for zip downloads

This commit is contained in:
Alan Grainger
2026-09-04 23:27:28 +12:00
parent ff45919107
commit 3701d4e92c
5 changed files with 20 additions and 3 deletions
+1
View File
@@ -136,6 +136,7 @@ function startZipResponse (res: Response, share: SharedLink, archive: Archiver)
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${filename}`)
// Hint to intermediate proxies (Nginx, etc.) not to buffer this response.
res.setHeader('X-Accel-Buffering', 'no')
res.setHeader('Cache-Control', 'no-store')
archive.pipe(res)
}
+3
View File
@@ -161,6 +161,9 @@ describe('downloadAssets', () => {
await downloadAssets(asResponse(res), share, [makeAsset('a1'), makeAsset('a2')])
expect(res.writableFinished).toBe(true)
expect(res.headers['Content-Type']).toBe('application/zip')
// A CDN must never store the zip; Cloudflare's cache fill aborts large
// downloads partway through otherwise #94
expect(res.headers['Cache-Control']).toBe('no-store')
const zip = res.output
expect(countOf(zip, 'PK\x03\x04')).toBe(2) // local file headers
expect(countOf(zip, 'PK\x05\x06')).toBe(1) // end of central directory