Skip to content

Commit d056241

Browse files
nilliganindexzero
authored andcommitted
fix 'Modify Response' readme section to avoid unnecessary array copying (#1300)
1 parent 244303b commit d056241

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,12 @@ data.
501501
selfHandleResponse : true
502502
};
503503
proxy.on('proxyRes', function (proxyRes, req, res) {
504-
var body = new Buffer('');
505-
proxyRes.on('data', function (data) {
506-
body = Buffer.concat([body, data]);
504+
var body = [];
505+
proxyRes.on('data', function (chunk) {
506+
body.push(chunk);
507507
});
508508
proxyRes.on('end', function () {
509-
body = body.toString();
509+
body = Buffer.concat(body).toString();
510510
console.log("res from proxied server:", body);
511511
res.end("my response to cli");
512512
});

0 commit comments

Comments
 (0)