Skip to content

Commit 442952e

Browse files
committed
fix(core): Webhooks responding with binary data should not prematurely end the response stream
1 parent 637b6c4 commit 442952e

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
@@ -561,11 +561,11 @@ export async function executeWebhook(
561561
if (binaryData?.id) {
562562
res.header(response.headers);
563563
const stream = await Container.get(BinaryDataService).getAsStream(binaryData.id);
564-
await pipeline(stream, res);
564+
await pipeline(stream, res, { end: false });
565565
responseCallback(null, { noWebhookResponse: true });
566566
} else if (Buffer.isBuffer(response.body)) {
567567
res.header(response.headers);
568-
res.end(response.body);
568+
res.write(response.body);
569569
responseCallback(null, { noWebhookResponse: true });
570570
} else {
571571
// TODO: This probably needs some more changes depending on the options on the
@@ -594,6 +594,7 @@ export async function executeWebhook(
594594
});
595595
}
596596

597+
res.end();
597598
didSendResponse = true;
598599
})
599600
.catch(async (error) => {
@@ -793,14 +794,15 @@ export async function executeWebhook(
793794
res.setHeader('Content-Type', binaryData.mimeType);
794795
if (binaryData.id) {
795796
const stream = await Container.get(BinaryDataService).getAsStream(binaryData.id);
796-
await pipeline(stream, res);
797+
await pipeline(stream, res, { end: false });
797798
} else {
798-
res.end(Buffer.from(binaryData.data, BINARY_ENCODING));
799+
res.write(Buffer.from(binaryData.data, BINARY_ENCODING));
799800
}
800801

801802
responseCallback(null, {
802803
noWebhookResponse: true,
803804
});
805+
res.end();
804806
}
805807
} else if (responseData === 'noData') {
806808
// Return without data

0 commit comments

Comments
 (0)