bun icon indicating copy to clipboard operation
bun copied to clipboard

Request.clone doesn't clone body

Open ariesclark opened this issue 3 years ago • 1 comments

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

ariesclark avatar Jul 29 '22 10:07 ariesclark

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

Jarred-Sumner avatar Jul 31 '22 01:07 Jarred-Sumner

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());

Electroid avatar Nov 03 '22 00:11 Electroid

This bug seems to have regressed in #6348, #6969 (and a bunch of other issues, this has been duplicated many times over)

dangeredwolf avatar Jan 22 '24 01:01 dangeredwolf