Skip to content

Commit 092781d

Browse files
fix: handle binary content properly in WebDAV requests (#1332)
Prevents corruption of binary files (images, videos, audio, PDFs) by passing streams through as-is instead of reading them as text for WebDAV content requests.
1 parent 0098a79 commit 092781d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

server/plugins/renderer/renderer.module.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,24 @@ internals.getResponse = async (request) => {
115115
const contentType = response.headers['content-type'] || '';
116116
const isResponseJson = contentType.toLowerCase().includes('application/json');
117117
const isWebDavRequest = request.path.startsWith('/content');
118+
const isBinaryContent = contentType
119+
.toLowerCase()
120+
.match(/^(image|video|audio|application\/octet-stream|application\/pdf)/);
118121
let bcAppData = response.data;
119122

120123
if (isResponseJson) {
121124
bcAppData = JSON.parse(await readFromStream(response.data));
122125
} else if (isWebDavRequest) {
123-
const tappedStream = tapStream(response.data, (body) => {
124-
return body;
125-
});
126-
bcAppData = await readStream(tappedStream);
126+
if (isBinaryContent) {
127+
// For binary content, don't read the stream - pass it through as-is
128+
bcAppData = response.data;
129+
} else {
130+
// For text content, read as string
131+
const tappedStream = tapStream(response.data, (body) => {
132+
return body;
133+
});
134+
bcAppData = await readStream(tappedStream, false);
135+
}
127136
}
128137
// cache response
129138
cache.put(

0 commit comments

Comments
 (0)