From 1703e9a541f02598f04cac8347d896ba2aee0187 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Tue, 16 Mar 2021 03:59:36 +0100 Subject: [PATCH] Moved http timeout cancelation before pipeline to prevent large files from getting canceled. --- src/utils/http.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/utils/http.js b/src/utils/http.js index 32e9a8b4..4573f833 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -80,7 +80,7 @@ function getLimiter(options = {}, url) { return limiters[interval][concurrency]; } -async function request(method = 'get', url, body, requestOptions = {}, limiter) { +async function request(method = 'get', url, body, requestOptions = {}, limiter, timeout) { const http = requestOptions.session || bhttp; const options = { @@ -107,7 +107,7 @@ async function request(method = 'get', url, body, requestOptions = {}, limiter) ? http[method](url, body, options) : http[method](url, options)); - const resIsOk = res.statusCode >= 200 && res.statusCode <= 299; + timeout.cancel(); if (options.destination) { // res.on('progress', (bytes, totalBytes) => logger.silly(`Downloaded ${Math.round((bytes / totalBytes) * 100)}% of ${url}`)); @@ -126,7 +126,7 @@ async function request(method = 'get', url, body, requestOptions = {}, limiter) status: res.statusCode, document: window.document, window, - ok: resIsOk, + ok: res.statusCode >= 200 && res.statusCode <= 299, }; } @@ -152,9 +152,7 @@ async function scheduleRequest(method = 'get', url, body, options) { const limiter = getLimiter(options, url); const timeout = getTimeout(options, url); - const result = await limiter.schedule(() => Promise.race([request(method, url, body, options, limiter), timeout])); - - timeout.cancel(); + const result = await limiter.schedule(() => Promise.race([request(method, url, body, options, limiter, timeout), timeout])); return result; }