Skip to content

feat: add stream pipe response#68

Merged
pi0 merged 6 commits intoh3js:mainfrom
stafyniaksacha:feat-streams
Mar 16, 2022
Merged

feat: add stream pipe response#68
pi0 merged 6 commits intoh3js:mainfrom
stafyniaksacha:feat-streams

Conversation

@stafyniaksacha
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread src/app.ts Outdated
@stafyniaksacha stafyniaksacha requested a review from pi0 March 15, 2022 19:51
Comment thread src/utils/response.ts Outdated
@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.

3 participants