From 9b8414e8b4be3c3a9babfc40a1962263ab3b97ce Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 12 Feb 2024 13:00:27 +0100 Subject: [PATCH] MOBILE-2768 mimetype: Improve mimetype detection for PHP URLs --- src/core/services/utils/utils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 312dc74d3..00c1e2729 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -749,16 +749,17 @@ export class CoreUtilsProvider { async getMimeTypeFromUrl(url: string): Promise { // First check if it can be guessed from the URL. const extension = CoreMimetypeUtils.guessExtensionFromUrl(url); - let mimetype = extension && CoreMimetypeUtils.getMimeType(extension); + const mimetype = extension && CoreMimetypeUtils.getMimeType(extension); - if (mimetype) { + // Ignore PHP extension for now, it could be serving a file. + if (mimetype && extension !== 'php') { return mimetype; } // Can't be guessed, get the remote mimetype. - mimetype = await CoreWS.getRemoteFileMimeType(url); + const remoteMimetype = await CoreWS.getRemoteFileMimeType(url); - return mimetype || ''; + return remoteMimetype || mimetype || ''; } /**