mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
d720d6affa
[web] send explicit content type in responses GitOrigin-RevId: d5aeaba57a7d2fc053fbf5adc2299fb46e435341
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
function csvAttachment(res, body, filename) {
|
|
if (!filename || !filename.endsWith('.csv')) {
|
|
throw new Error('filename must end with .csv')
|
|
}
|
|
// res.attachment sets both content-type and content-disposition headers.
|
|
res.attachment(filename)
|
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
res.send(body)
|
|
}
|
|
|
|
function preparePlainTextResponse(res) {
|
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
res.contentType('text/plain; charset=utf-8')
|
|
}
|
|
|
|
function plainTextResponse(res, body) {
|
|
preparePlainTextResponse(res)
|
|
res.send(body)
|
|
}
|
|
|
|
function xmlResponse(res, body) {
|
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
res.contentType('application/xml; charset=utf-8')
|
|
res.send(body)
|
|
}
|
|
|
|
function prepareZipAttachment(res, filename) {
|
|
if (!filename || !filename.endsWith('.zip')) {
|
|
throw new Error('filename must end with .zip')
|
|
}
|
|
// res.attachment sets both content-type and content-disposition headers.
|
|
res.attachment(filename)
|
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
}
|
|
|
|
function zipAttachment(res, body, filename) {
|
|
prepareZipAttachment(res, filename)
|
|
res.send(body)
|
|
}
|
|
|
|
module.exports = {
|
|
csvAttachment,
|
|
plainTextResponse,
|
|
preparePlainTextResponse,
|
|
prepareZipAttachment,
|
|
xmlResponse,
|
|
zipAttachment,
|
|
}
|