From 714c726973cf27ca0a66d8c8c7896609701e844a Mon Sep 17 00:00:00 2001 From: Fredrik Lindberg Date: Thu, 24 Jun 2021 10:21:51 +0200 Subject: [PATCH] fix(http-captor): 'data' might not be the first listener attached --- src/utils/http-captor.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/http-captor.js b/src/utils/http-captor.js index 4273d6b..3a31621 100644 --- a/src/utils/http-captor.js +++ b/src/utils/http-captor.js @@ -100,11 +100,13 @@ class HttpCaptor { } }; - this._request.once('newListener', (event, listener) => { + const onListener = (event, listener) => { if (event === 'data') { + this._request.off('newListener', onListener); this._request.on('data', handleData); } - }); + }; + this._request.on('newListener', onListener); this._request.once('end', done); this._request.once('error', done); });