"Modify Response" example code has problems
Created by: nilligan
This section of the README: https://github.com/nodejitsu/node-http-proxy#modify-response
It suggests that you should use body = Buffer.concat([body, data]);
for every chunk received. This causes performance issues for large requests, since the Buffer.concat
unnecessarily creates a new copy of the Buffer on every chunk.
The NodeJS docs suggest a different approach: pushing each chunk to a mutable array, with only one Buffer.concat
in the "end" event: https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/#request-body
let body = [];
request.on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
});
Happy to submit a PR