bun
bun copied to clipboard
Pass `Request` object to `Request` constructor doesn't work with `ReadableStream` body
What version of Bun is running?
1.0.15
What platform is your computer?
No response
What steps can reproduce the bug?
Code
// index.mjs
const body = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode('yay'))
controller.close()
}
})
const request = new Request('http://localhost', {
body,
method: 'POST',
duplex: 'half'
})
const req = new Request(request)
console.log(await req.text())
Run
bun run index.mjs
What is the expected behavior?
Console output
yay
What do you see instead?
Console output
Additional information
The same code works as expected in Node.js (v18.16.0
& v21.4.0
), run node index.mjs
This works already in Bun:
const request = new Request('http://localhost', { body: 'yay', method: 'POST' })
const req = new Request(request)
console.log(await req.text()) // "yay"
I noticed that the following code does not work in Bun. Is this intended? (same behavior; should print yay
as above)
const server = Bun.serve({
port: 8080,
async fetch(request) {
const req = new Request(request)
return new Response(await req.text())
}
})
const res = await fetch('http://localhost:8080', {
method: 'POST',
body: 'yay'
})
console.log(await res.text())
server.stop()
I'm being blocked by this. The implementation of effect rpc (https://github.com/Effect-TS/effect) uses ReadableStream to stream the reponse to the client. I'm seeing the same issue, the response body is empty on the client.