MOBILE-3833 ws: Send User Agent in file transfer requests

main
Dani Palou 2022-03-17 12:15:03 +01:00
parent 68708d116b
commit e5ba19a835
2 changed files with 13 additions and 4 deletions

View File

@ -113,7 +113,10 @@ export class FileTransferObjectMock extends FileTransferObject {
xhr.open('GET', source, true);
xhr.responseType = 'blob';
for (const name in headers) {
xhr.setRequestHeader(name, headers[name]);
// We can't set the User-Agent in browser.
if (name !== 'User-Agent') {
xhr.setRequestHeader(name, headers[name]);
}
}
xhr.onprogress = (ev: ProgressEvent): void => {
@ -332,7 +335,7 @@ export class FileTransferObjectMock extends FileTransferObject {
xhr.open(httpMethod || 'POST', url);
for (const name in headers) {
// Filter "unsafe" headers.
if (name != 'Connection') {
if (name !=='Connection' && name !== 'User-Agent') {
xhr.setRequestHeader(name, headers[name]);
}
}

View File

@ -270,7 +270,11 @@ export class CoreWSProvider {
onProgress && transfer.onProgress(onProgress);
// Download the file in the tmp file.
await transfer.download(url, fileEntry.toURL(), true);
await transfer.download(url, fileEntry.toURL(), true, {
headers: {
'User-Agent': navigator.userAgent, // eslint-disable-line @typescript-eslint/naming-convention
},
});
let extension = '';
@ -885,7 +889,9 @@ export class CoreWSProvider {
itemid: options.itemId || 0,
};
options.chunkedMode = false;
options.headers = {};
options.headers = {
'User-Agent': navigator.userAgent, // eslint-disable-line @typescript-eslint/naming-convention
};
options['Connection'] = 'close';
let success: FileUploadResult;