diff --git a/filemode.js b/filemode.js index cfb59e8..2601cc7 100644 --- a/filemode.js +++ b/filemode.js @@ -108,6 +108,15 @@ async function handleFile(req, res, config) { return; } + // 1б) Content-Length больше лимита — отказ БЕЗ чтения тела. Иначе при + // превышении в процессе чтения мы вынуждены оборвать поток (req.destroy()), + // и клиент получает обрыв соединения вместо чистого 413. См. assist.js. + const declaredLen = Number.parseInt(req.headers['content-length'], 10); + if (Number.isFinite(declaredLen) && declaredLen > MAX_BODY) { + jsonError(res, 413, 413, 'body too large'); + return; + } + // 2) Тело с лимитом + разбор {content, instruction}. const read = await readBody(req); if (!read.ok) {