randomize User-Agent

The VBB endpoint blocks all requests with the exact User-Agent of
"https://github.com/public-transport/hafas-client".
This commit is contained in:
Jannis R 2018-07-25 11:36:40 +02:00
parent b6c530915f
commit d54c26d9be
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -9,6 +9,8 @@ const {stringify} = require('query-string')
const Promise = require('pinkie-promise')
const {fetch} = require('fetch-ponyfill')({Promise})
const clientId = Math.random().toString(16).substr(2, 10)
const md5 = input => createHash('md5').update(input).digest()
const request = (profile, data) => {
@ -21,7 +23,7 @@ const request = (profile, data) => {
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate',
'Accept': 'application/json',
'user-agent': 'https://github.com/public-transport/hafas-client'
'user-agent': clientId + ' https://github.com/public-transport/hafas-client'
},
query: {}
})