bun icon indicating copy to clipboard operation
bun copied to clipboard

`Request.clone()` does not clone body

Open Electroid opened this issue 2 years ago • 3 comments

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

Electroid avatar Oct 23 '22 21:10 Electroid

Need to do .tee() on ReadableStream. It clones it for non-streaming bodies (same for Response)

Jarred-Sumner avatar Oct 23 '22 21:10 Jarred-Sumner

You can use .tee() but this should still work, see example here. (send a POST request with "{}" body)

Electroid avatar Oct 23 '22 21:10 Electroid

Sorry - I meant Bun needs to internally call tee(). It is a bug that this doesn't work right now

Jarred-Sumner avatar Oct 23 '22 21:10 Jarred-Sumner

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

JustGreg avatar Jul 26 '23 13:07 JustGreg

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 :-|

beorn avatar May 28 '24 22:05 beorn