bun
bun copied to clipboard
Request.clone doesn't clone body
Version
0.1.5
Platform
Linux 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
What steps will reproduce the bug?
// this works, the body is logged.
Bun.serve({
fetch: async (request) => {
console.log(await request.json())
return Response.json({})
}
})
// this doesn't work, no body.
Bun.serve({
fetch: async (request) => {
console.log(await request.clone().json())
return Response.json({})
}
})
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
No body 💀
Additional information
No response
Ah, the bug is here:
https://github.com/oven-sh/bun/blob/7b7b4b46af2f829fee72b8474fd6af697bae6d8c/src/bun.js/webcore/response.zig#L4095-L4097
It should be cloning it when Body == .Locked, but it isn't
Fixed as of 0.2.2, tested using:
const request = new Request("http://localhost/", { body: "{\"data\":1}" });
console.log(await request.clone().json());
console.log(await request.json());
This bug seems to have regressed in #6348, #6969 (and a bunch of other issues, this has been duplicated many times over)