request: tweak user-agent randomisation

see also https://github.com/deg0nz/MMM-PublicTransportBerlin/pull/67
This commit is contained in:
Jannis R 2022-01-13 13:55:17 +01:00
parent 2ec079adfc
commit e3a022972c
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -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()