Skip to content

Commit

Permalink
Merge pull request #19582 from dhdaines/consume_response
Browse files Browse the repository at this point in the history
Be sure to consume responses in case of error in downloading test files (issue 19580)
  • Loading branch information
timvandermeij authored Mar 2, 2025
2 parents 1aee9d5 + 962f972 commit e8bbb60
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/downloadutils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function downloadFile(file, url, redirects = 0) {
.get(url, async function (response) {
if ([301, 302, 307, 308].includes(response.statusCode)) {
if (redirects > 10) {
response.resume();
reject(new Error("Too many redirects"));
return;
}
Expand All @@ -50,12 +51,14 @@ function downloadFile(file, url, redirects = 0) {
await downloadFile(file, redirectTo, ++redirects);
resolve();
} catch (ex) {
response.resume();
reject(ex);
}
return;
}

if (response.statusCode !== 200) {
response.resume();
reject(new Error(`HTTP ${response.statusCode}`));
return;
}
Expand Down

0 comments on commit e8bbb60

Please sign in to comment.