const http = require('http'), assert = require('assert'), { readBody } = require('../body'); const s = http.createServer(async (req, res) => { try { const t = await readBody(req, 1000); res.end('ok:' + t.length); } catch (e) { res.writeHead(e.status || 500); res.end(e.message); } }); s.listen(0, async () => { const P = s.address().port, post = b => fetch(`http://127.0.0.1:${P}/`, { method: 'POST', body: b }).then(async r => [r.status, await r.text()]); assert.deepStrictEqual(await post('x'.repeat(900)), [200, 'ok:900']); const big = await post('x'.repeat(5000)); assert.strictEqual(big[0], 413); console.log('body test ok'); s.close(); });