mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 05:12:29 +00:00
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 <jarred@jarredsumner.com>
This commit is contained in:
@@ -2723,7 +2723,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
|
||||
}
|
||||
|
||||
pub fn doRender(this: *RequestContext) void {
|
||||
ctxLog("render", .{});
|
||||
ctxLog("doRender", .{});
|
||||
|
||||
if (this.flags.aborted) {
|
||||
this.finalizeForAbort();
|
||||
@@ -3039,7 +3039,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
|
||||
|
||||
if (last) {
|
||||
var bytes = this.request_body_buf;
|
||||
defer this.request_body_buf = .{};
|
||||
|
||||
var old = body.value;
|
||||
|
||||
const total = bytes.items.len + chunk.len;
|
||||
@@ -3070,6 +3070,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
|
||||
};
|
||||
// }
|
||||
}
|
||||
this.request_body_buf = .{};
|
||||
|
||||
if (old == .Locked) {
|
||||
var vm = this.server.vm;
|
||||
|
||||
@@ -1716,7 +1716,7 @@ pub const VirtualMachine = struct {
|
||||
printed,
|
||||
),
|
||||
};
|
||||
res.* = ErrorableString.err(error.NameTooLong, ResolveMessage.create(global, VirtualMachine.get().allocator, msg, source.utf8()).asVoid());
|
||||
res.* = ErrorableString.err(error.NameTooLong, ResolveMessage.create(global, VirtualMachine.get().allocator, msg, source_utf8.slice()).asVoid());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
20
test/js/bun/http/big-form-data.fixture.js
Normal file
20
test/js/bun/http/big-form-data.fixture.js
Normal file
@@ -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);
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user