Limit request sizes, answer 413, stop cleanly on SIGTERM
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UaC9HmtHMdRP8dAbN4wAKj
This commit is contained in:
8 files changed
+29
-6
No files matched your search
@@ -0,0 +1,8 @@
|
||||
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();
|
||||
});
|
||||
Reference in new issue
Block a user