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

feat: add stream pipe response #68

Merged
merged 6 commits into from
Mar 16, 2022
Merged

Conversation

stafyniaksacha
Copy link
Contributor

This allows to pipe readable streams returned from middlewares!

I also set the default content-type header used for buffers and streams to text/html assuming most of time it would be used to pipe html response. We could use application/octet-stream instead, but it would require to explicitly set content-type on each responses.

@danielroe
Copy link
Member

Very nice thought. However, it looks like this adds a hard dependency on node, which we would want to avoid. Maybe something other than instanceof as a test?

@stafyniaksacha
Copy link
Contributor Author

stafyniaksacha commented Mar 15, 2022

Very nice thought. However, it looks like this adds a hard dependency on node, which we would want to avoid. Maybe something other than instanceof as a test?

Hum, that's true. Using deno or web workers would rely on ReadableStream which is the new standard.

This uses the former node streams. Instead we can rely on the new stream implementation, so we can check over pipeTo method instead of instanceof.

The caveat is that the feature is new and require node v16, what do you think?

Edit: unfortunately we can not use pipeTo on http responses for now, even with node 17

src/app.ts Outdated Show resolved Hide resolved
@stafyniaksacha stafyniaksacha requested a review from pi0 March 15, 2022 19:51
src/utils/response.ts Outdated Show resolved Hide resolved
@stafyniaksacha stafyniaksacha requested a review from pi0 March 15, 2022 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants