Setting user agent #2117
-
|
Hello everyone, how would one go about setting the user agent on a client? I have included my code below for reference class RequestSession {
constructor(proxy) {
const splitProxy = proxy.split(":");
const formattedProxy = `http://${splitProxy[2]}:${splitProxy[3]}@${splitProxy[0]}:${splitProxy[1]}`
this.jar = new CookieJar();
this.client = got.extend({
agent: {
http: new HttpsProxyAgent(formattedProxy),
},
cookieJar: this.jar,
});
}
request = async (options) => {
return await this.client(options);
}
}Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Answered by
DanielHougaard
Aug 24, 2022
Replies: 1 comment
-
|
Hi again. I missed a crucial part of the documentation and I have just found the solution. this.client = got.extend({
headers: { // This!
'user-agent': // Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36....
},
agent: {
http: new HttpsProxyAgent(formattedProxy),
},
cookieJar: this.jar,
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sindresorhus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi again. I missed a crucial part of the documentation and I have just found the solution.
For anyone else wondering, it's done by passing 'user-agent' in the instance headers like so: