From fa2ef0972b11de2be5ecd5c92f13f56d6890c2ad Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Wed, 13 Sep 2023 21:48:30 -0700 Subject: fix(Bun.serve) fix buffering edge case (#5152) * fix buffering clean * fix resolveMaybeNeedsTrailingSlash and try to fix ci/cd error * fix resolveMaybeNeedsTrailingSlash and try to fix ci/cd error * oops --------- Co-authored-by: Jarred Sumner --- test/js/bun/http/big-form-data.fixture.js | 20 ++++++++++++++++++++ test/js/bun/http/bun-server.test.ts | 11 +++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/js/bun/http/big-form-data.fixture.js (limited to 'test/js') diff --git a/test/js/bun/http/big-form-data.fixture.js b/test/js/bun/http/big-form-data.fixture.js new file mode 100644 index 000000000..72036a222 --- /dev/null +++ b/test/js/bun/http/big-form-data.fixture.js @@ -0,0 +1,20 @@ +const content = "Bun".repeat(15360000); + +const server = Bun.serve({ + port: 0, + fetch: async req => { + const data = await req.formData(); + return new Response(data.get("name") === content ? "OK" : "NO"); + }, +}); + +const formData = new FormData(); +formData.append("name", content); +const result = await fetch(`http://${server.hostname}:${server.port}`, { + method: "POST", + body: formData, +}).then(res => res.text()); + +server.stop(); + +process.exit(result === "OK" ? 0 : 1); diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index 3e0e4e71e..398ef4bb7 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from "bun:test"; +import { bunExe, bunEnv } from "harness"; describe("Server", () => { test("normlizes incoming request URLs", async () => { @@ -357,4 +358,14 @@ describe("Server", () => { server.stop(true); } }); + + test("should not crash with big formData", async () => { + const proc = Bun.spawn({ + cmd: [bunExe(), "big-form-data.fixture.js"], + cwd: import.meta.dir, + env: bunEnv, + }); + await proc.exited; + expect(proc.exitCode).toBe(0); + }); }); -- cgit v1.2.3