Skip to content
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

"Modify Response" example code has problems #1277

Closed
nilligan opened this issue Jun 22, 2018 · 2 comments · Fixed by #1300
Closed

"Modify Response" example code has problems #1277

nilligan opened this issue Jun 22, 2018 · 2 comments · Fixed by #1300

Comments

@nilligan
Copy link
Contributor

nilligan commented Jun 22, 2018

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

@prmichaelsen
Copy link

Good call

@indexzero
Copy link
Contributor

Fixed in #1300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants