Update utils.js

This commit is contained in:
Aleksandr Statciuk 2021-10-13 23:02:06 +03:00
parent 7e0d7437cb
commit 63796646bb
1 changed files with 6 additions and 0 deletions

View File

@ -163,11 +163,17 @@ utils.writeToFile = function (filename, data) {
}
utils.buildRequest = async function (item, config) {
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const request = { ...config.request }
const timeout = setTimeout(() => {
source.cancel('Connection timeout')
}, request.timeout)
const headers = await utils.getRequestHeaders(item, config)
request.headers = { 'User-Agent': defaultUserAgent, ...headers }
request.url = await utils.getRequestUrl(item, config)
request.data = await utils.getRequestData(item, config)
request.cancelToken = source.token
if (config.debug) {
console.log('Request:', JSON.stringify(request, null, 2))