Skip to content

Commit 335d613

Browse files
committed
Ensure all data is read, not just first chunk
1 parent e7dc5f8 commit 335d613

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

scripts/test-rest.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ console.log(`...Testing connection to REST API at ${restUrl}...\n`);
2222
if (appConfig.rest.ssl) {
2323
const req = https.request(restUrl, (res) => {
2424
console.log(`RESPONSE: ${res.statusCode} ${res.statusMessage} \n`);
25-
res.on('data', (data) => {
25+
// We will keep reading data until the 'end' event fires.
26+
// This ensures we don't just read the first chunk.
27+
let data = '';
28+
res.on('data', (chunk) => {
29+
data += chunk;
30+
});
31+
res.on('end', () => {
2632
checkJSONResponse(data);
2733
});
2834
});
@@ -35,7 +41,13 @@ if (appConfig.rest.ssl) {
3541
} else {
3642
const req = http.request(restUrl, (res) => {
3743
console.log(`RESPONSE: ${res.statusCode} ${res.statusMessage} \n`);
38-
res.on('data', (data) => {
44+
// We will keep reading data until the 'end' event fires.
45+
// This ensures we don't just read the first chunk.
46+
let data = '';
47+
res.on('data', (chunk) => {
48+
data += chunk;
49+
});
50+
res.on('end', () => {
3951
checkJSONResponse(data);
4052
});
4153
});

0 commit comments

Comments
 (0)