forked from DebaucheryLibrarian/traxxx
Moved http timeout cancelation before pipeline to prevent large files from getting canceled.
This commit is contained in:
parent
ece9569d66
commit
1703e9a541
|
@ -80,7 +80,7 @@ function getLimiter(options = {}, url) {
|
||||||
return limiters[interval][concurrency];
|
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 http = requestOptions.session || bhttp;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -107,7 +107,7 @@ async function request(method = 'get', url, body, requestOptions = {}, limiter)
|
||||||
? http[method](url, body, options)
|
? http[method](url, body, options)
|
||||||
: http[method](url, options));
|
: http[method](url, options));
|
||||||
|
|
||||||
const resIsOk = res.statusCode >= 200 && res.statusCode <= 299;
|
timeout.cancel();
|
||||||
|
|
||||||
if (options.destination) {
|
if (options.destination) {
|
||||||
// res.on('progress', (bytes, totalBytes) => logger.silly(`Downloaded ${Math.round((bytes / totalBytes) * 100)}% of ${url}`));
|
// 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,
|
status: res.statusCode,
|
||||||
document: window.document,
|
document: window.document,
|
||||||
window,
|
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 limiter = getLimiter(options, url);
|
||||||
const timeout = getTimeout(options, url);
|
const timeout = getTimeout(options, url);
|
||||||
|
|
||||||
const result = await limiter.schedule(() => Promise.race([request(method, url, body, options, limiter), timeout]));
|
const result = await limiter.schedule(() => Promise.race([request(method, url, body, options, limiter, timeout), timeout]));
|
||||||
|
|
||||||
timeout.cancel();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue