-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
fix(cloneIncomingMessage): inherit prototype properties #214
Conversation
99f6c2c
to
8dde721
Compare
Hey, @hrsh7th! Thank you for submitting this fix.
This may be an issue, as we're exposing the cloned
When the consumer adds a Maybe we can think of reusing parts of your solution to preserve the prototype? Would that be possible? |
I've tested this locally on node16 re-using the same workflow that the github actions has and it works great! Regarding the types, this function as it existed before and after this PR forces the type by casting to unknown and then to ClonedIncomingMessage. The stream itself has the same overall shape but it now has the prototype methods added in. If you remove the 'to unknown' part tsc has a way better idea about the type of the stream and it seems like it's been the wrong one for quite some time. Like if you look at the shape of an IncomingMessage vs what's there in |
I'd changed the implementation to support This approach can be broken if both |
I think this PR is ready to review and merge. 👍🏼 |
expect(clone).toBeInstanceOf(IncomingMessage) | ||
expect(clone).toBeInstanceOf(EventEmitter) | ||
expect(clone).toBeInstanceOf(Stream) | ||
expect(clone).toBeInstanceOf(Readable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm adding assertions to check that the cloned message indeed extends all the prototypes of the original message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely fantastic job on this one, @hrsh7th! 🎉
Thank you for making this library better. Welcome to contributors!
🎉 This PR is included in version 0.13.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thank you for review, fix and merge! 🎉 |
Fix #212
The current implementation will clone the properties defined in
instance
.But the
headers
property defined inprototype
in Node.js v16 or higher.So this PR aims to support prototype inheriting in
cloneIncomingMessage
.Fixed.