Use array + join, instead of append for request body strings

This commit is contained in:
absidue
2021-10-28 18:57:44 +02:00
parent 533aebc2ff
commit a13e588246
2 changed files with 6 additions and 4 deletions

View File

@@ -69,6 +69,7 @@ export class Proxy {
return new Promise((resolve, reject) => {
this.socket.setEncoding('utf-8');
this.socket.once('error', (err) => reject(err));
const parts: string[] = [];
this.socket.on('data', (chunk: string) => {
if (this.rawHeaders.length === 0) {
this.rawHeaders = chunk;
@@ -76,10 +77,11 @@ export class Proxy {
} else {
const arr = chunk.split('\r\n');
if (arr.length > 1 && arr[0].length < 5) arr.shift();
this.body += arr.join('');
parts.push(...arr);
}
});
this.socket.on('end', () => {
this.body = parts.join('');
resolve(this);
});
});