From e5ba19a835c1263e01ad0413c6cb2dacb42cbc5d Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 17 Mar 2022 12:15:03 +0100 Subject: [PATCH] MOBILE-3833 ws: Send User Agent in file transfer requests --- src/core/features/emulator/services/file-transfer.ts | 7 +++++-- src/core/services/ws.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/features/emulator/services/file-transfer.ts b/src/core/features/emulator/services/file-transfer.ts index 59961318f..63f8baa8f 100644 --- a/src/core/features/emulator/services/file-transfer.ts +++ b/src/core/features/emulator/services/file-transfer.ts @@ -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]); } } diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 866ed0724..9d9e270de 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -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;