Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request.clone() does not clone body #1381

Open
Electroid opened this issue Oct 23, 2022 · 5 comments · May be fixed by #1693, #3908 or #8668
Open

Request.clone() does not clone body #1381

Electroid opened this issue Oct 23, 2022 · 5 comments · May be fixed by #1693, #3908 or #8668
Labels
bug Something isn't working web-api Something that relates to a standard Web API

Comments

@Electroid
Copy link
Contributor

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 Electroid added the bug Something isn't working label Oct 23, 2022
@Jarred-Sumner
Copy link
Collaborator

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

@Electroid
Copy link
Contributor Author

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

@Jarred-Sumner
Copy link
Collaborator

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

@zhiyuang zhiyuang linked a pull request Jan 1, 2023 that will close this issue
@JustGreg
Copy link

is there any progress on this issue?

#2477
honojs/middleware#81 (comment)
#1693

@beorn
Copy link

beorn commented May 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working web-api Something that relates to a standard Web API
Projects
None yet
4 participants