Skip to content

Commit 6a4e03b

Browse files
committed
fix(core): Webhooks responding with binary data should not prematurely end the response stream
1 parent 0a2de09 commit 6a4e03b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/cli/src/WebhookHelpers.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,11 @@ export async function executeWebhook(
562562
if (binaryData?.id) {
563563
res.header(response.headers);
564564
const stream = await Container.get(BinaryDataService).getAsStream(binaryData.id);
565-
await pipeline(stream, res);
565+
await pipeline(stream, res, { end: false });
566566
responseCallback(null, { noWebhookResponse: true });
567567
} else if (Buffer.isBuffer(response.body)) {
568568
res.header(response.headers);
569-
res.end(response.body);
569+
res.write(response.body);
570570
responseCallback(null, { noWebhookResponse: true });
571571
} else {
572572
// TODO: This probably needs some more changes depending on the options on the
@@ -595,6 +595,7 @@ export async function executeWebhook(
595595
});
596596
}
597597

598+
res.end();
598599
didSendResponse = true;
599600
})
600601
.catch(async (error) => {
@@ -795,14 +796,15 @@ export async function executeWebhook(
795796
res.setHeader('Content-Type', binaryData.mimeType);
796797
if (binaryData.id) {
797798
const stream = await Container.get(BinaryDataService).getAsStream(binaryData.id);
798-
await pipeline(stream, res);
799+
await pipeline(stream, res, { end: false });
799800
} else {
800-
res.end(Buffer.from(binaryData.data, BINARY_ENCODING));
801+
res.write(Buffer.from(binaryData.data, BINARY_ENCODING));
801802
}
802803

803804
responseCallback(null, {
804805
noWebhookResponse: true,
805806
});
807+
res.end();
806808
}
807809
} else if (responseData === 'noData') {
808810
// Return without data

0 commit comments

Comments
 (0)