[web] disable buffering when downloading large files (#31874)

* [web] disable buffering when downloading large files

* [web] fix unit tests

GitOrigin-RevId: c8b0381962814fa62425364f03457600daf287ef
This commit is contained in:
Jakob Ackermann
2026-03-02 10:02:23 +01:00
committed by Copybot
parent 89e8044a25
commit da50aee52c
5 changed files with 14 additions and 0 deletions

View File

@@ -105,6 +105,10 @@ async function _downloadFromCacheWithParams(
const TEN_MINUTES_IN_MS = 10 * 60 * 1000
res.setTimeout(TEN_MINUTES_IN_MS)
timer = setTimeout(() => ac.abort(), TEN_MINUTES_IN_MS)
// Disable buffering in nginx
res.setHeader('X-Accel-Buffering', 'no')
try {
res.writeHead(response.status)
await pipeline(

View File

@@ -632,6 +632,9 @@ const _CompileController = {
clearTimeout(timeout)
timeout = setTimeout(() => ac.abort(), TEN_MINUTES_IN_MS)
// Disable buffering in nginx
res.setHeader('X-Accel-Buffering', 'no')
res.writeHead(response.status)
await pipeline(stream, res)
timer.labels.status = 'success'

View File

@@ -89,6 +89,9 @@ async function requestBlob(method, req, res) {
res.setHeader('Content-Type', 'application/octet-stream')
setBlobCacheHeaders(res, hash)
// Disable buffering in nginx
res.setHeader('X-Accel-Buffering', 'no')
try {
await pipeline(stream, res)
} catch (err) {

View File

@@ -31,6 +31,8 @@ export function prepareZipAttachment(res, filename) {
// res.attachment sets both content-type and content-disposition headers.
res.attachment(filename)
res.setHeader('X-Content-Type-Options', 'nosniff')
// Disable buffering in nginx
res.setHeader('X-Accel-Buffering', 'no')
}
export function zipAttachment(res, body, filename) {

View File

@@ -113,6 +113,7 @@ describe('ProjectDownloadsController', function () {
ctx.res.headers.should.deep.equal({
'Content-Disposition': `attachment; filename="project_name_with_accênts_and___special_characters.zip"`,
'Content-Type': 'application/zip',
'X-Accel-Buffering': 'no',
'X-Content-Type-Options': 'nosniff',
})
})
@@ -184,6 +185,7 @@ describe('ProjectDownloadsController', function () {
'Content-Disposition':
'attachment; filename="Overleaf Projects (2 items).zip"',
'Content-Type': 'application/zip',
'X-Accel-Buffering': 'no',
'X-Content-Type-Options': 'nosniff',
})
})