Moved http timeout cancelation before pipeline to prevent large files from getting canceled.

This commit is contained in:
DebaucheryLibrarian 2021-03-16 03:59:36 +01:00
parent ece9569d66
commit 1703e9a541
1 changed files with 4 additions and 6 deletions

View File

@ -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;
}