From 50c4ead23ba83717d3611c4c13d6681f5e448725 Mon Sep 17 00:00:00 2001 From: Nytelife26 Date: Mon, 12 Apr 2021 14:56:16 +0100 Subject: [PATCH] feat: use buffer length when available --- src/lib/PetitioResponse.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/PetitioResponse.ts b/src/lib/PetitioResponse.ts index 66f8339..bf328df 100644 --- a/src/lib/PetitioResponse.ts +++ b/src/lib/PetitioResponse.ts @@ -25,11 +25,12 @@ export class PetitioResponse { /** * This takes the data chunks and creates a Buffer, and it sets * that buffer as the body. - * @param {*} chunk The chunk of data to append to the body. + * @param {*} chunks The body to set for the response. * @return {*} In place operation with no return. */ - public _addBody(chunk: Buffer[] | Uint8Array[]) { - this.body = Buffer.concat(chunk); + public _addBody(chunks: Buffer[] | Uint8Array[]) { + const length = this.headers["content-length"]; + this.body = Buffer.concat(chunks, length ? Number(length) : undefined); } /**