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

Stream compression does not work when res.body is a stream (no res.stream) #8

Open
btakita opened this issue Dec 14, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@btakita
Copy link

btakita commented Dec 14, 2023

When returning a ReadableStream from an Elysia route, .body is the ReadableStream while .stream is undefined.

The code in question is:

https:/Gusb3ll/elysia-compression/blob/main/src/index.ts#L76C42-L76C42

Not only does the stream not compress, but the response is hijacked to be {} instead of the html.

To fix, I inserted:

const stream = ctx.response?.stream ?? ctx.response?.body;

Edit:

I have never seen res.stream before. Is this in the web standard or is this something added by Elysia or Bun?

Note the route looks something like:

app.get('/', ()=>
  new Response(
    new ReadableStream({
      start(controller) {
        controller.enqueue('<html></html>')
        controller.close()
      }
    }),
    {
      headers: { 'Content-Type': 'text/html;charset=UTF-8' }
    }
  ))
@Gusb3ll Gusb3ll added the bug Something isn't working label Dec 16, 2023
@Gusb3ll Gusb3ll self-assigned this Dec 16, 2023
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