From 335d613df7b5aaf05ea38cf3e271b4739a1db901 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Mon, 12 Sep 2022 12:43:03 -0500 Subject: [PATCH] Ensure all data is read, not just first chunk --- scripts/test-rest.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/test-rest.ts b/scripts/test-rest.ts index b2a3ebd1af..51822cf939 100644 --- a/scripts/test-rest.ts +++ b/scripts/test-rest.ts @@ -22,7 +22,13 @@ console.log(`...Testing connection to REST API at ${restUrl}...\n`); if (appConfig.rest.ssl) { const req = https.request(restUrl, (res) => { console.log(`RESPONSE: ${res.statusCode} ${res.statusMessage} \n`); - res.on('data', (data) => { + // We will keep reading data until the 'end' event fires. + // This ensures we don't just read the first chunk. + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { checkJSONResponse(data); }); }); @@ -35,7 +41,13 @@ if (appConfig.rest.ssl) { } else { const req = http.request(restUrl, (res) => { console.log(`RESPONSE: ${res.statusCode} ${res.statusMessage} \n`); - res.on('data', (data) => { + // We will keep reading data until the 'end' event fires. + // This ensures we don't just read the first chunk. + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { checkJSONResponse(data); }); });