diff --git a/src/app.ts b/src/app.ts index 4ff3536f..58598bdc 100644 --- a/src/app.ts +++ b/src/app.ts @@ -60,6 +60,7 @@ async function configureApp() { // Only accept json as content type if (contentType === '' || contentType.match(/^application\/json$/) === null) { + // return an error in the response const err = new SCUnsupportedMediaTypeErrorResponse(isTestEnvironment); res.status(err.statusCode); res.json(err); @@ -67,17 +68,21 @@ async function configureApp() { } const bodyBuffer: any[] = []; + // we don't know the full size, the only way we can get is by adding up all individual chunk sizes let bodySize = 0; const chunkGatherer = (chunk: Buffer) => { bodySize += chunk.byteLength; + // when adding each chunk size to the total size, check how large it now is. if (bodySize > 512 * 1024) { req.off('data', chunkGatherer); req.off('end', endCallback); + // return an error in the response const err = new SCRequestBodyTooLargeErrorResponse(isTestEnvironment); res.status(err.statusCode); res.json(err); return; } + // push the chunk in the buffer bodyBuffer.push(chunk); };