fix(download): ask reverse proxies not to buffer file downloads (#604)

Send X-Accel-Buffering: no on file download responses so nginx and
compatible reverse proxies stream them through instead of buffering, the
usual cause of a self-hosted download that "starts but never finishes".
The app already delivers exactly Content-Length bytes; a new real-socket
test proves it for both the collated PDF and the multi-file ZIP.

Refs #590
This commit is contained in:
SnapOtter
2026-07-21 17:02:12 +08:00
committed by GitHub
parent e7ffb37e98
commit 89d75853f4
2 changed files with 88 additions and 0 deletions
+5
View File
@@ -120,6 +120,11 @@ export async function fileRoutes(app: FastifyInstance): Promise<void> {
// Check Range header before setting content headers (a 416 must not
// carry the attachment Content-Type that would confuse serialization).
reply.header("Accept-Ranges", "bytes");
// Tell nginx (and compatible reverse proxies) not to buffer the download.
// A buffering proxy in front of a self-hosted install is the usual cause
// of a download that "starts but never finishes"; the app itself always
// delivers exactly Content-Length bytes. Mirrors the SSE route (#590).
reply.header("X-Accel-Buffering", "no");
const range = request.headers.range;
if (range) {