From c7b80825bc170862574d8f4e1827a59da2d07737 Mon Sep 17 00:00:00 2001 From: driphtyio Date: Thu, 18 Jun 2026 14:54:02 -0700 Subject: [PATCH] fix: serve zero-size files (e.g. /proc) with proper content When stat.size === 0 (e.g. /proc virtual filesystem files), don't limit the read stream to byte 0 and don't set Content-Length: 0. Let the stream read until EOF and use chunked transfer encoding. Fixes expressjs/express#4944 --- index.js | 8 ++++++-- test/send.js | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1655053..4836893 100644 --- a/index.js +++ b/index.js @@ -577,10 +577,14 @@ SendStream.prototype.send = function send (path, stat) { // set read options opts.start = offset - opts.end = Math.max(offset, offset + len - 1) + if (len > 0) { + opts.end = Math.max(offset, offset + len - 1) + } // content-length - res.setHeader('Content-Length', len) + if (len > 0) { + res.setHeader('Content-Length', len) + } // HEAD support if (req.method === 'HEAD') { diff --git a/test/send.js b/test/send.js index b824282..2f26e12 100644 --- a/test/send.js +++ b/test/send.js @@ -35,7 +35,6 @@ describe('send(file).pipe(res)', function () { it('should stream a zero-length file', function (done) { request(app) .get('/empty.txt') - .expect('Content-Length', '0') .expect(200, '', done) })