I want to manually create http.IncomingMessage stream with some header & body. As it is a readable stream, I can't write/pipe data into it. Is it safe to extend it?
Also, I am not sure how to store headers when it's a stream which doesn't operate on ObjectMode.
EDIT:
According to Node.js documentation, extending http.IncomingMessage is possible.
IncomingMessage <http.IncomingMessage> Specifies the IncomingMessage class to be used. Useful for extending the original IncomingMessage. Default: IncomingMessage.
How can I extend it? Its constructor asks for Socket object.
I mocked it like this in my tests:
import { IncomingMessage } from "http";
import { Socket } from "net";
const msg = new IncomingMessage(new Socket());
msg.method = 'POST';
msg.url = "whateverurl"
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With