Skip to content

Commit 4ae3877

Browse files
committed
Prevent from server down when request body has nothing
How to reproduce - Build a bot with 'botbuilder' and 'express' - Send a request without body - Server down Sample request: % curl -X POST http://localhost:3978/api/messages Stack trace SyntaxError: Unexpected end of JSON input at Object.parse (native) at IncomingMessage.<anonymous> (botbuilder/lib/bots/ChatConnector.js:43:37) at emitNone (events.js:86:13) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:975:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9) Reference: https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/#header-request-body
1 parent 4539822 commit 4ae3877

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Node/core/lib/bots/ChatConnector.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ var ChatConnector = (function () {
3535
_this.verifyBotFramework(req, res);
3636
}
3737
else {
38-
var requestData = '';
38+
var requestData = [];
3939
req.on('data', function (chunk) {
40-
requestData += chunk;
41-
});
42-
req.on('end', function () {
43-
req.body = JSON.parse(requestData);
40+
requestData.push(chunk)
41+
}).on('end', function () {
42+
req.body = Buffer.concat(body).toString();
4443
_this.verifyBotFramework(req, res);
4544
});
4645
}

0 commit comments

Comments
 (0)