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

Add support for HTTP stream instances #21

Merged
merged 1 commit into from
Feb 19, 2024
Merged

Add support for HTTP stream instances #21

merged 1 commit into from
Feb 19, 2024

Conversation

ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Feb 19, 2024

Fixes #8.

This adds support for IncomingMessage, OutgoingMessage, ServerResponse and ClientRequest from the http core module. Those inherit from a legacy Stream base class then add stream methods manually, so their inheritance is a little odd, but they follow the stream's documented API. This is due to avoid double buffering, for performance reasons.

This PR relies on documented fields for the streams API, instead of the current approach which uses undocumented ones. This was suggested in #8 (comment), and seems to make sense.

I also included fields like readableObjectMode/writableObjectMode so we are sure we are dealing with Node.js streams since those property names are quite specific.

In principle, this should not be a breaking change. However, it is not impossible for someone to be passing weird stream objects which do not follow the documented streams API. Therefore, to be on the safe side, it might be good to consider it a breaking change, even if it should not be in principle.

@sindresorhus sindresorhus merged commit 45e90c2 into sindresorhus:main Feb 19, 2024
1 check passed
@ehmicky ehmicky deleted the support-server-response branch February 19, 2024 16:44
@ehmicky ehmicky mentioned this pull request Feb 19, 2024
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.

isStream.writable() returns false for http.ServerResponse
2 participants