Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request #246 from soketi/fix/crash-on-empty-post
[fix] Do not close the connection on empty POST payload
  • Loading branch information
rennokki committed Jan 7, 2022
2 parents 53ba39c + 8541e4e commit 4b12efe
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/http-handler.ts
Expand Up @@ -417,19 +417,22 @@ export class HttpHandler {
let chunk = Buffer.from(ab);

if (isLast) {
let json;
let raw;
let json = {};
let raw = '{}';

if (buffer) {
try {
// @ts-ignore
json = JSON.parse(Buffer.concat([buffer, chunk]));
} catch (e) {
res.close();
return;
//
}

raw = Buffer.concat([buffer, chunk]).toString();
try {
raw = Buffer.concat([buffer, chunk]).toString();
} catch (e) {
//
}

cb(json, raw);
loggingAction(json);
Expand All @@ -439,8 +442,7 @@ export class HttpHandler {
json = JSON.parse(chunk);
raw = chunk.toString();
} catch (e) {
res.close();
return;
//
}

cb(json, raw);
Expand Down

0 comments on commit 4b12efe

Please sign in to comment.