Skip to content

"Modify Response" example code has problems #1277

Closed
@nilligan

Description

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions