Add version number to user-agent header on outgoing requests

This commit is contained in:
Scott Nonnenberg 2020-01-16 16:53:35 -08:00
parent be6ae038dc
commit a271fe0eee
3 changed files with 20 additions and 4 deletions

View file

@ -210,7 +210,7 @@ function _promiseAjax(providedUrl, options) {
method: options.type,
body: options.data || null,
headers: {
'User-Agent': 'Signal Desktop (+https://signal.org/download)',
'User-Agent': `Signal Desktop ${options.version}`,
'X-Signal-Agent': 'OWD',
...options.headers,
},
@ -413,6 +413,7 @@ function initialize({
certificateAuthority,
contentProxyUrl,
proxyUrl,
version,
}) {
if (!is.string(url)) {
throw new Error('WebAPI.initialize: Invalid server url');
@ -426,6 +427,9 @@ function initialize({
if (!is.string(contentProxyUrl)) {
throw new Error('WebAPI.initialize: Invalid contentProxyUrl');
}
if (!is.string(version)) {
throw new Error('WebAPI.initialize: Invalid version');
}
// Thanks to function-hoisting, we can put this return statement before all of the
// below function definitions.
@ -489,6 +493,7 @@ function initialize({
type: param.httpType,
user: username,
validateResponse: param.validateResponse,
version,
unauthenticated: param.unauthenticated,
accessKey: param.accessKey,
}).catch(e => {
@ -576,6 +581,7 @@ function initialize({
responseType: 'arraybuffer',
timeout: 0,
type: 'GET',
version,
});
}
@ -855,6 +861,7 @@ function initialize({
responseType: 'arraybuffer',
type: 'GET',
redactUrl: redactStickerUrl,
version,
});
}
@ -865,6 +872,7 @@ function initialize({
responseType: 'arraybuffer',
type: 'GET',
redactUrl: redactStickerUrl,
version,
});
}
@ -942,6 +950,7 @@ function initialize({
timeout: 0,
type: 'POST',
processData: false,
version,
});
// Upload stickers
@ -957,6 +966,7 @@ function initialize({
timeout: 0,
type: 'POST',
processData: false,
version,
})
);
if (onProgress) {
@ -977,6 +987,7 @@ function initialize({
responseType: 'arraybuffer',
timeout: 0,
type: 'GET',
version,
});
}
@ -999,6 +1010,7 @@ function initialize({
timeout: 0,
type: 'POST',
processData: false,
version,
});
return attachmentIdString;
@ -1036,6 +1048,7 @@ function initialize({
redirect: 'follow',
redactUrl: () => '[REDACTED_URL]',
headers,
version,
});
if (!returnArrayBuffer) {
@ -1071,9 +1084,10 @@ function initialize({
.replace('http://', 'ws://');
const login = encodeURIComponent(username);
const pass = encodeURIComponent(password);
const clientVersion = encodeURIComponent(version);
return _createSocket(
`${fixedScheme}/v1/websocket/?login=${login}&password=${pass}&agent=OWD`,
`${fixedScheme}/v1/websocket/?login=${login}&password=${pass}&agent=OWD&version=${clientVersion}`,
{ certificateAuthority, proxyUrl }
);
}
@ -1083,9 +1097,10 @@ function initialize({
const fixedScheme = url
.replace('https://', 'wss://')
.replace('http://', 'ws://');
const clientVersion = encodeURIComponent(version);
return _createSocket(
`${fixedScheme}/v1/websocket/provisioning/?agent=OWD`,
`${fixedScheme}/v1/websocket/provisioning/?agent=OWD&version=${clientVersion}`,
{ certificateAuthority, proxyUrl }
);
}

View file

@ -246,6 +246,7 @@ window.WebAPI = initializeWebAPI({
certificateAuthority: config.certificateAuthority,
contentProxyUrl: config.contentProxyUrl,
proxyUrl: config.proxyUrl,
version: config.version,
});
// Linux seems to periodically let the event loop stop, so this is a global workaround

View file

@ -273,7 +273,7 @@ function getGotOptions(): GotOptions<null> {
ca,
headers: {
'Cache-Control': 'no-cache',
'User-Agent': 'Signal Desktop (+https://signal.org/download)',
'User-Agent': `Signal Desktop ${packageJson.version}`,
},
useElectronNet: false,
};