Add setContentDisposition() utility function.

It checks if a request has a `filename` search parameter and if
so, set the Content-Disposition response header to attachment
with the provided filename.
This commit is contained in:
D. Berge
2023-10-29 11:35:26 +01:00
parent a74fd56f15
commit 013a52ff55
2 changed files with 10 additions and 1 deletions

View File

@@ -8,5 +8,6 @@ module.exports = {
removeNulls: require('./removeNulls'), removeNulls: require('./removeNulls'),
logicalPath: require('./logicalPath'), logicalPath: require('./logicalPath'),
ranges: require('./ranges'), ranges: require('./ranges'),
unique: require('./unique') unique: require('./unique'),
setContentDisposition: require('./setContentDisposition')
}; };

View File

@@ -0,0 +1,8 @@
function setContentDisposition (req, res) {
if (req.query.filename) {
res.set("Content-Disposition", `attachment; filename="${req.query.filename}"`);
}
}
module.exports = setContentDisposition;