Fix UTF-8 request body handling
This commit is contained in:
@@ -92,17 +92,19 @@ async function writeDatabase(data) {
|
||||
|
||||
function readRequestBody(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let body = '';
|
||||
const chunks = [];
|
||||
let bodyLength = 0;
|
||||
|
||||
request.on('data', (chunk) => {
|
||||
body += chunk;
|
||||
if (body.length > 5_000_000) {
|
||||
chunks.push(chunk);
|
||||
bodyLength += chunk.length;
|
||||
if (bodyLength > 5_000_000) {
|
||||
reject(new Error('Request body is too large'));
|
||||
request.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
request.on('end', () => resolve(body));
|
||||
request.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
||||
request.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user