Skip to content

Commit 09b7e33

Browse files
committed
feat: file helper also sets Content-Length response header
1 parent 395a31d commit 09b7e33

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

helpers/file.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const fs = require('fs');
22

33
module.exports = filePath => (req, res) => {
4+
const stat = fs.statSync(filePath);
5+
6+
res.setHeader('Content-Length', stat.size);
7+
48
fs.createReadStream(filePath).pipe(res);
59
};

test/mock-helpers.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('Helpers', () => {
3333
request(app)
3434
.get('/api/users/avatar')
3535
.expect('Content-Type', 'image/png')
36+
.expect('Content-Length', '0')
3637
.expect(200, done);
3738
});
3839
});

0 commit comments

Comments
 (0)