mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
docs: added some inline comments
This commit is contained in:
committed by
Rainer Killinger
parent
e70e50a1ea
commit
eabd885cd4
@@ -60,6 +60,7 @@ async function configureApp() {
|
|||||||
|
|
||||||
// Only accept json as content type
|
// Only accept json as content type
|
||||||
if (contentType === '' || contentType.match(/^application\/json$/) === null) {
|
if (contentType === '' || contentType.match(/^application\/json$/) === null) {
|
||||||
|
// return an error in the response
|
||||||
const err = new SCUnsupportedMediaTypeErrorResponse(isTestEnvironment);
|
const err = new SCUnsupportedMediaTypeErrorResponse(isTestEnvironment);
|
||||||
res.status(err.statusCode);
|
res.status(err.statusCode);
|
||||||
res.json(err);
|
res.json(err);
|
||||||
@@ -67,17 +68,21 @@ async function configureApp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bodyBuffer: any[] = [];
|
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;
|
let bodySize = 0;
|
||||||
const chunkGatherer = (chunk: Buffer) => {
|
const chunkGatherer = (chunk: Buffer) => {
|
||||||
bodySize += chunk.byteLength;
|
bodySize += chunk.byteLength;
|
||||||
|
// when adding each chunk size to the total size, check how large it now is.
|
||||||
if (bodySize > 512 * 1024) {
|
if (bodySize > 512 * 1024) {
|
||||||
req.off('data', chunkGatherer);
|
req.off('data', chunkGatherer);
|
||||||
req.off('end', endCallback);
|
req.off('end', endCallback);
|
||||||
|
// return an error in the response
|
||||||
const err = new SCRequestBodyTooLargeErrorResponse(isTestEnvironment);
|
const err = new SCRequestBodyTooLargeErrorResponse(isTestEnvironment);
|
||||||
res.status(err.statusCode);
|
res.status(err.statusCode);
|
||||||
res.json(err);
|
res.json(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// push the chunk in the buffer
|
||||||
bodyBuffer.push(chunk);
|
bodyBuffer.push(chunk);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user