Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function (err) {
proxy.inUse = false
// handle timeout as Broken proxy
if(BlockErrors.indexOf(err.code) !== -1) {
if(!proxy.broken) {
proxy.broken = new Date()
proxy.errors++
logger.warn('added ' + proxy.proxy + ' to broken list for host ' + url.host + ' (' + err.code + ')')
if(Proxies.allBroken()) {
logger.error('all proxies are broken')
}
}
}
else {
logger.error(err)
}
}
}
return function (err) {
proxy.inUse = false
// handle timeout as Broken proxy
if(BlockErrors.indexOf(err.code) !== -1) {
if(!proxy.broken) {
proxy.broken = new Date()
proxy.errors++
logger.warn('added ' + proxy.proxy + ' to broken list for host ' + url.host + ' (' + err.code + ')')
if(Proxies.allBroken()) {
logger.error('all proxies are broken')
}
}
}
else {
logger.error(err)
}
}
}
return function (err, response, body) {
proxy.inUse = false
if(GraceTime !== 0) proxy.lastRequest = new Date()
if(err) {
res.writeHead(500, {
'Content-Length': err.message? err.message.length: 0,
'Content-Type': 'text/plain',
'x-proxy': proxy.proxy
})
res.status(500).end(err.message || '')
return
} else if(response.statusCode === 403) {
logger.error(proxy.proxy + ' is blocked')
proxy.blocked = new Date()
if(Proxies.allBlocked()) {
logger.error('all proxies are blocked')
}
return setTimeout(function() {
handleRequest(req, res)
}, NextReqTimeout)
}
var header = response.headers
proxy.hits++
header['x-proxy'] = proxy.proxy
res.writeHead(response.statusCode, header)
res.end(body)
}
}
return function (err, response, body) {
proxy.inUse = false
if(GraceTime !== 0) proxy.lastRequest = new Date()
if(err) {
res.writeHead(500, {
'Content-Length': err.message? err.message.length: 0,
'Content-Type': 'text/plain',
'x-proxy': proxy.proxy
})
res.status(500).end(err.message || '')
return
} else if(response.statusCode === 403) {
logger.error(proxy.proxy + ' is blocked')
proxy.blocked = new Date()
if(Proxies.allBlocked()) {
logger.error('all proxies are blocked')
}
return setTimeout(function() {
handleRequest(req, res)
}, NextReqTimeout)
}
var header = response.headers
proxy.hits++
header['x-proxy'] = proxy.proxy
res.writeHead(response.statusCode, header)
res.end(body)
}
}