mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
## Summary Improves server stability when handling certain request edge cases. ## Test plan - Added regression test in `test/regression/issue/22353.test.ts` - Test verifies server continues operating normally after handling edge case requests - All existing HTTP server tests pass Fixes #22353 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
38 lines
916 B
TypeScript
38 lines
916 B
TypeScript
import { expect, test } from "bun:test";
|
|
|
|
test("issue #22353 - server should handle oversized request without crashing", async () => {
|
|
using server = Bun.serve({
|
|
port: 0,
|
|
maxRequestBodySize: 1024, // 1KB limit
|
|
async fetch(req) {
|
|
const body = await req.text();
|
|
return new Response(
|
|
JSON.stringify({
|
|
received: true,
|
|
size: body.length,
|
|
}),
|
|
{
|
|
headers: { "Content-Type": "application/json" },
|
|
},
|
|
);
|
|
},
|
|
});
|
|
|
|
const resp = await fetch(server.url, {
|
|
method: "POST",
|
|
body: "A".repeat(1025),
|
|
});
|
|
expect(resp.status).toBe(413);
|
|
expect(await resp.text()).toBeEmpty();
|
|
for (let i = 0; i < 100; i++) {
|
|
const resp2 = await fetch(server.url, {
|
|
method: "POST",
|
|
});
|
|
expect(resp2.status).toBe(200);
|
|
expect(await resp2.json()).toEqual({
|
|
received: true,
|
|
size: 0,
|
|
});
|
|
}
|
|
}, 10000);
|