mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
request: tweak user-agent randomisation
see also https://github.com/deg0nz/MMM-PublicTransportBerlin/pull/67
This commit is contained in:
parent
2ec079adfc
commit
e3a022972c
1 changed files with 11 additions and 3 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue