Skip to content
Snippets Groups Projects
Unverified Commit 36bcec8e authored by Noach Magedman's avatar Noach Magedman Committed by Diego Sampaio
Browse files

fix: Improve FileProxy Handling, set Content-Type (#30427)

parent 3f7ce23a
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
---
Forward headers when using proxy for file uploads
...@@ -562,7 +562,32 @@ export const FileUpload = { ...@@ -562,7 +562,32 @@ export const FileUpload = {
) { ) {
res.setHeader('Content-Disposition', `${forceDownload ? 'attachment' : 'inline'}; filename="${encodeURI(fileName)}"`); res.setHeader('Content-Disposition', `${forceDownload ? 'attachment' : 'inline'}; filename="${encodeURI(fileName)}"`);
request.get(fileUrl, (fileRes) => fileRes.pipe(res)); request.get(fileUrl, (fileRes) => {
if (fileRes.statusCode !== 200) {
res.setHeader('x-rc-proxyfile-status', String(fileRes.statusCode));
res.setHeader('content-length', 0);
res.writeHead(500);
res.end();
return;
}
// eslint-disable-next-line prettier/prettier
const headersToProxy = [
'age',
'cache-control',
'content-length',
'content-type',
'date',
'expired',
'last-modified',
];
headersToProxy.forEach((header) => {
fileRes.headers[header] && res.setHeader(header, String(fileRes.headers[header]));
});
fileRes.pipe(res);
});
}, },
generateJWTToFileUrls({ rid, userId, fileId }: { rid: string; userId: string; fileId: string }) { generateJWTToFileUrls({ rid, userId, fileId }: { rid: string; userId: string; fileId: string }) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment