Skip to content
20 changes: 16 additions & 4 deletions lib/network.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
'use strict';

const receiveBody = async (stream) => {
const MAX_BODY_SIZE = 10 * 1024 * 1024;

const receiveBody = async (stream, limit = MAX_BODY_SIZE) => {
Comment thread
tshemsedinov marked this conversation as resolved.
if (!Number.isSafeInteger(limit) || limit < 0) {
throw new TypeError('Body size limit must be a non-negative safe integer');
}
const chunks = [];
for await (const chunk of stream) chunks.push(chunk);
return Buffer.concat(chunks);
let size = 0;
for await (const chunk of stream) {
size += chunk.length;
if (size > limit) {
throw new Error('Body size limit exceeded');
}
chunks.push(chunk);
}
return Buffer.concat(chunks, size);
};

const IPV4_OCTETS = 4;
Expand Down Expand Up @@ -50,4 +62,4 @@
ipToInt,
intToIp,
httpApiCall,
};
};

Check failure on line 65 in lib/network.js

View workflow job for this annotation

GitHub Actions / build (24, macos-latest)

Newline required at end of file but not found

Check failure on line 65 in lib/network.js

View workflow job for this annotation

GitHub Actions / build (22, macos-latest)

Newline required at end of file but not found

Check failure on line 65 in lib/network.js

View workflow job for this annotation

GitHub Actions / build (24, ubuntu-latest)

Newline required at end of file but not found

Check failure on line 65 in lib/network.js

View workflow job for this annotation

GitHub Actions / build (18, ubuntu-latest)

Newline required at end of file but not found

Check failure on line 65 in lib/network.js

View workflow job for this annotation

GitHub Actions / build (20, ubuntu-latest)

Newline required at end of file but not found

Check failure on line 65 in lib/network.js

View workflow job for this annotation

GitHub Actions / build (22, ubuntu-latest)

Newline required at end of file but not found
Comment thread
tshemsedinov marked this conversation as resolved.
Comment thread
tshemsedinov marked this conversation as resolved.
Loading