feat(REST): append additional information to the required User Agent (#6112)

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
Joey Smalen
2021-07-16 13:27:12 +02:00
committed by GitHub
parent 8db6df3d1e
commit f200f14a40
4 changed files with 15 additions and 2 deletions

View File

@@ -17,6 +17,9 @@ class APIRequest {
this.options = options;
this.retries = 0;
const { userAgentSuffix } = this.client.options;
this.fullUserAgent = `${UserAgent}${userAgentSuffix.length ? `, ${userAgentSuffix.join(', ')}` : ''}`;
let queryString = '';
if (options.query) {
const query = Object.entries(options.query)
@@ -33,11 +36,14 @@ class APIRequest {
? this.client.options.http.api
: `${this.client.options.http.api}/v${this.client.options.http.version}`;
const url = API + this.path;
let headers = { ...this.client.options.http.headers };
let headers = {
...this.client.options.http.headers,
'User-Agent': this.fullUserAgent,
};
if (this.options.auth !== false) headers.Authorization = this.rest.getAuth();
if (this.options.reason) headers['X-Audit-Log-Reason'] = encodeURIComponent(this.options.reason);
headers['User-Agent'] = UserAgent;
if (this.options.headers) headers = Object.assign(headers, this.options.headers);
let body;