mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
better User-Agent randomization 🐛
This commit is contained in:
parent
0b81a59c71
commit
50bd4409f5
2 changed files with 9 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,3 +4,5 @@ Thumbs.db
|
|||
.nvm-version
|
||||
node_modules
|
||||
npm-debug.log
|
||||
|
||||
/id.json
|
||||
|
|
|
@ -9,10 +9,16 @@ const {stringify} = require('query-string')
|
|||
const Promise = require('pinkie-promise')
|
||||
const {fetch} = require('fetch-ponyfill')({Promise})
|
||||
|
||||
const userAgent = 'https://github.com/public-transport/hafas-client'
|
||||
const clientId = Math.random().toString(16).substr(2, 10)
|
||||
|
||||
const md5 = input => createHash('md5').update(input).digest()
|
||||
|
||||
const randomizeUserAgent = () => {
|
||||
const i = Math.round(Math.random() * userAgent.length)
|
||||
return userAgent.slice(0, i) + clientId + userAgent.slice(i)
|
||||
}
|
||||
|
||||
const request = (profile, data) => {
|
||||
const body = profile.transformReqBody({lang: 'en', svcReqL: [data]})
|
||||
const req = profile.transformReq({
|
||||
|
@ -23,7 +29,7 @@ const request = (profile, data) => {
|
|||
'Content-Type': 'application/json',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': 'application/json',
|
||||
'user-agent': clientId + ' https://github.com/public-transport/hafas-client'
|
||||
'user-agent': randomizeUserAgent()
|
||||
},
|
||||
query: {}
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue