Skip to content

Commit

Permalink
feat: file helper also sets Content-Length response header
Browse files Browse the repository at this point in the history
  • Loading branch information
muratcorlu committed Apr 25, 2020
1 parent 395a31d commit 09b7e33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions helpers/file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const fs = require('fs');

module.exports = filePath => (req, res) => {
const stat = fs.statSync(filePath);

res.setHeader('Content-Length', stat.size);

fs.createReadStream(filePath).pipe(res);
};
1 change: 1 addition & 0 deletions test/mock-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Helpers', () => {
request(app)
.get('/api/users/avatar')
.expect('Content-Type', 'image/png')
.expect('Content-Length', '0')
.expect(200, done);
});
});

0 comments on commit 09b7e33

Please sign in to comment.