clone-response
Clone a Node.js HTTP response stream
Returns a new stream and copies over all properties and methods from the original response giving you a complete duplicate.
This is useful in situations where you need to consume the response stream but also want to pass an unconsumed stream somewhere else to be consumed later.
Install
npm install --save clone-response
Usage
const http = require('http');
const cloneResponse = require('clone-response');
http.get('http://example.com', response => {
const clonedResponse = cloneResponse(response);
response.pipe(process.stdout);
setImmediate(() => {
doSomethingWithResponse(clonedResponse);
});
});
Please bear in mind that the process of cloning a stream consumes it. However, you can consume a stream multiple times in the same tick, therefore allowing you to create multiple clones. e.g:
const clone1 = cloneResponse(response);
const clone2 = cloneResponse(response);
API
cloneResponse(response)
Returns a clone of the passed in response.
response
Type: stream
A Node.js HTTP response stream to clone.
License
MIT © Luke Childs