diff --git a/lib/request.js b/lib/request.js index 76384193..bd976052 100644 --- a/lib/request.js +++ b/lib/request.js @@ -51,10 +51,18 @@ if (proxyAddress) { getAgent = () => pool.get() } -const id = randomBytes(6).toString('hex') +const id = randomBytes(3).toString('hex') const randomizeUserAgent = (userAgent) => { - const i = Math.round(Math.random() * userAgent.length) - return userAgent.slice(0, i) + id + userAgent.slice(i) + let ua = userAgent + for ( + let i = Math.round(5 + Math.random() * 5); + i < ua.length; + i += Math.round(5 + Math.random() * 5) + ) { + ua = ua.slice(0, i) + id + ua.slice(i) + i += id.length + } + return ua } const md5 = input => createHash('md5').update(input).digest()