Skip to content

Commit

Permalink
fix(core): Webhooks responding with binary data should not prematurel…
Browse files Browse the repository at this point in the history
…y end the response stream
  • Loading branch information
netroy committed Apr 4, 2024
1 parent 637b6c4 commit 442952e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,11 @@ export async function executeWebhook(
if (binaryData?.id) {
res.header(response.headers);
const stream = await Container.get(BinaryDataService).getAsStream(binaryData.id);
await pipeline(stream, res);
await pipeline(stream, res, { end: false });
responseCallback(null, { noWebhookResponse: true });
} else if (Buffer.isBuffer(response.body)) {
res.header(response.headers);
res.end(response.body);
res.write(response.body);
responseCallback(null, { noWebhookResponse: true });
} else {
// TODO: This probably needs some more changes depending on the options on the
Expand Down Expand Up @@ -594,6 +594,7 @@ export async function executeWebhook(
});
}

res.end();
didSendResponse = true;
})
.catch(async (error) => {
Expand Down Expand Up @@ -793,14 +794,15 @@ export async function executeWebhook(
res.setHeader('Content-Type', binaryData.mimeType);
if (binaryData.id) {
const stream = await Container.get(BinaryDataService).getAsStream(binaryData.id);
await pipeline(stream, res);
await pipeline(stream, res, { end: false });
} else {
res.end(Buffer.from(binaryData.data, BINARY_ENCODING));
res.write(Buffer.from(binaryData.data, BINARY_ENCODING));
}

responseCallback(null, {
noWebhookResponse: true,
});
res.end();
}
} else if (responseData === 'noData') {
// Return without data
Expand Down

0 comments on commit 442952e

Please sign in to comment.