From d335ad57fc7274981a90a2dc3e2c329a6bd8ad69 Mon Sep 17 00:00:00 2001 From: Oj Date: Fri, 4 Feb 2022 20:45:15 +0000 Subject: [PATCH] [Poly > Request] Add encoding null support --- polyfills/request.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polyfills/request.js b/polyfills/request.js index 612fb34..602d230 100644 --- a/polyfills/request.js +++ b/polyfills/request.js @@ -58,16 +58,16 @@ const request = (...args) => { listeners['response']?.(res); - let body = ''; - + let data = []; res.on('data', (chunk) => { - body += chunk; + data.push(chunk); listeners['data']?.(chunk); }); await new Promise((resolve) => res.on('end', resolve)); // Wait to read full body - callback?.(undefined, res, body); + const buf = Buffer.concat(data); + callback?.(undefined, res, options.encoding !== null ? buf.toString() : buf); }); const ret = {