An extension of the Node.js Transform stream that additionally supports the HTTP header interface.
RequestPair: creates a pair of related streams, one writable, one readable; anything written to the clientWritableSide is readable on the serverReadableSide.
ResponsePair: creates a pair of related streams, one writable, one readable; anything written to the serverWritableSide is readable on the clientReadableSide.
ResponsePassThrough: creates a Duplex stream that also stores HTTP headers; anything written to it becomes readable. Headers are passed through as exactly as possible. It should typically possible to pipe a response through a ResponsePassThrough instance with no change in behavior. This is typically used to programmatically create a response that's readable the same way a Node.js req object is, and can be piped to a res server response object.
TODO
RequestPassThrough — Request variation of ResponsePassThrough
RequestThroughOrigin — subclass of RequestPair that applies header normalizations, as if the request is actually going through the network.
ResponseThroughOrigin — subclass of ResponsePair that applies header normalizations, as if the response is actually going through the network.
Features
Mock a readable response object:
function makeResponse(){ const res = new ResponsePassThrough; res.setHeader('Content-Type', 'text/plain') res.write('Line\r\n'); return res.readableClientSide;}