bun
bun copied to clipboard
`Request.clone()` does not clone body
What version of Bun is running?
0.2.1 (canary)
What platform is your computer?
Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 20:57:23 PDT 2022; root:xnu-8020.121.3~2/RELEASE_ARM64_T8110 arm64 arm
What steps can reproduce the bug?
export default {
async fetch(request) {
console.log(".clone().json()", await request.clone().json());
console.log(".json()", await request.json());
return new Response("Ok");
}
}
curl -d '{}' http://localhost:3000
How often does it reproduce? Is there a required condition?
Always. Same with .text()
.
What is the expected behavior?
No response
What do you see instead?
Terminal output:
.clone().json() # body is missing
.json() {} # works fine
Additional information
No response
Need to do .tee() on ReadableStream. It clones it for non-streaming bodies (same for Response)
You can use .tee()
but this should still work, see example here. (send a POST request with "{}" body)
Sorry - I meant Bun needs to internally call tee(). It is a bug that this doesn't work right now
is there any progress on this issue?
https://github.com/oven-sh/bun/issues/2477 https://github.com/honojs/middleware/issues/81#issuecomment-1509457656 https://github.com/oven-sh/bun/pull/1693
This is causing all kinds of weird (and hard-to-track down) problems for people that do new Request(req)
type stuff. Would really appreciate it being prioritized :-|