From 1ccf8ac3a9b403f2e55e75f530b08c139d0c9ba0 Mon Sep 17 00:00:00 2001 From: Aga Date: Wed, 16 Oct 2024 12:20:55 +0200 Subject: [PATCH] chore: sync main to dev (#2460) --- .../MediaStream/OpenMediaPromise.cs | 6 +++++- .../WebRequestControllerExtensions.cs | 17 +++++++++++++++-- .../Scripts/Global/Dynamic/RealmController.cs | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Explorer/Assets/DCL/SDKComponents/MediaStream/OpenMediaPromise.cs b/Explorer/Assets/DCL/SDKComponents/MediaStream/OpenMediaPromise.cs index b20c8384f5..59bf3d5e0b 100644 --- a/Explorer/Assets/DCL/SDKComponents/MediaStream/OpenMediaPromise.cs +++ b/Explorer/Assets/DCL/SDKComponents/MediaStream/OpenMediaPromise.cs @@ -27,7 +27,11 @@ public async UniTask UrlReachabilityResolveAsync(IWebRequestController webReques isReachable = false; this.url = url; - isReachable = await webRequestController.IsReachableAsync(reportData, URLAddress.FromString(this.url), ct); + isReachable = await webRequestController.IsHeadReachableAsync(reportData, URLAddress.FromString(this.url), ct); + //This is needed because some servers might not handle HEAD requests correctly and return 404 errors, even thou they are perfectly + if (!isReachable) + isReachable = await webRequestController.IsGetReachableAsync(reportData, URLAddress.FromString(this.url), ct); + ReportHub.Log(ReportCategory.MEDIA_STREAM, $"Resource <{url}> isReachable = <{isReachable}>"); status = Status.Resolved; diff --git a/Explorer/Assets/DCL/WebRequests/WebRequestControllerExtensions.cs b/Explorer/Assets/DCL/WebRequests/WebRequestControllerExtensions.cs index d735c93677..866734ac22 100644 --- a/Explorer/Assets/DCL/WebRequests/WebRequestControllerExtensions.cs +++ b/Explorer/Assets/DCL/WebRequests/WebRequestControllerExtensions.cs @@ -149,7 +149,7 @@ public static UniTask HeadAsync( WebRequestSignInfo? signInfo = null) where TOp: struct, IWebRequestOp => controller.SendAsync(HEAD_GENERIC, commonArguments, arguments, webRequestOp, ct, reportCategory, headersInfo, signInfo); - public static async UniTask IsReachableAsync(this IWebRequestController controller, ReportData reportData, URLAddress url, CancellationToken ct) + public static async UniTask IsHeadReachableAsync(this IWebRequestController controller, ReportData reportData, URLAddress url, CancellationToken ct) { await UniTask.SwitchToMainThread(); @@ -168,7 +168,6 @@ public static async UniTask IsReachableAsync(this IWebRequestController co case WebRequestUtils.NOT_FOUND: return false; } - // Assume everything else means that there is such an endpoint for Non-HEAD ops return true; } @@ -177,6 +176,20 @@ public static async UniTask IsReachableAsync(this IWebRequestController co return true; } + public static async UniTask IsGetReachableAsync(this IWebRequestController controller, ReportData reportData, URLAddress url, CancellationToken ct) + { + await UniTask.SwitchToMainThread(); + + try { await GetAsync, WebRequestUtils.NoResult>(controller, new CommonArguments(url), new WebRequestUtils.NoOp(), ct, reportData); } + catch (UnityWebRequestException) + { + return false; + } + + return true; + } + + /// /// Make a request that is optimized for texture creation /// diff --git a/Explorer/Assets/Scripts/Global/Dynamic/RealmController.cs b/Explorer/Assets/Scripts/Global/Dynamic/RealmController.cs index 070cbc04fe..832bd8ed93 100644 --- a/Explorer/Assets/Scripts/Global/Dynamic/RealmController.cs +++ b/Explorer/Assets/Scripts/Global/Dynamic/RealmController.cs @@ -138,7 +138,7 @@ public async UniTask RestartRealmAsync(CancellationToken ct) } public async UniTask IsReachableAsync(URLDomain realm, CancellationToken ct) => - await webRequestController.IsReachableAsync(ReportCategory.REALM, realm.Append(new URLPath("/about")), ct); + await webRequestController.IsHeadReachableAsync(ReportCategory.REALM, realm.Append(new URLPath("/about")), ct); public async UniTask[]> WaitForFixedScenePromisesAsync(CancellationToken ct) {