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

ReadableStream used as fetch body is null in Bun.serve #10655

Open
TomasHubelbauer opened this issue Apr 29, 2024 · 2 comments
Open

ReadableStream used as fetch body is null in Bun.serve #10655

TomasHubelbauer opened this issue Apr 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@TomasHubelbauer
Copy link

TomasHubelbauer commented Apr 29, 2024

What version of Bun is running?

1.1.5

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

https://github.com/TomasHubelbauer/bun-passthrough-server

const textDecoder = new TextDecoder();

const server = Bun.serve({
  async fetch(request) {
    const url = new URL(request.url);
    switch (url.pathname) {
      case "/produce": {
        // @ts-expect-error Bun types?
        return new Response(async function* () {
          while (true) {
            const line = new Date().toISOString();
            yield line + "\n";
            console.log("Produced:", line);
            await Bun.sleep(1000);
          }
        });
      }
      case "/consume": {
        // @ts-expect-error Bun types?
        for await (const chunk of request.body) {
          console.log("Consumed:", textDecoder.decode(chunk));
        }

        return new Response();
      }
    }

    throw new Error("Not Found");
  },
});

const response = await fetch(`http://localhost:${server.port}/produce`);
await fetch(`http://localhost:${server.port}/consume`, {
  method: "POST",
  body: response.body,
});

What is the expected behavior?

For every "Produced" line, there should be a corresponding "Consumed" line.

What do you see instead?

request.body is null in the /consume switch branch.

Additional information

No response

@TomasHubelbauer TomasHubelbauer added the bug Something isn't working label Apr 29, 2024
@TomasHubelbauer
Copy link
Author

I guess this is a duplicate of #7206? I am not sure. I would expect this to work OOTB, even without duplex but I guess that's not what the fetch standard dictates.

@guest271314
Copy link
Contributor

duplex: "half" (HTTP/2) is not supported in bun. Yes, this is a duplicate of #7206.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants