From 3840fb4e8442f8961de605befb1df5030175f8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 30 Mar 2020 11:49:47 +0200 Subject: [PATCH] SEBWIN-362: Implemented fallback mechanism in case HEAD requests do not work for certain network resources. --- .../DataResources/NetworkResourceLoader.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs b/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs index 6686c19f..6010c006 100644 --- a/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs +++ b/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs @@ -163,6 +163,17 @@ namespace SafeExamBrowser.Configuration.DataResources logger.Debug($"Received response '{ToString(response)}'."); + if (!isAvailable) + { + logger.Debug($"HEAD request was not successful, trying GET request for '{uri}'..."); + + request = new HttpRequestMessage(HttpMethod.Get, uri); + response = Execute(request); + isAvailable = response.IsSuccessStatusCode || IsUnauthorized(response); + + logger.Debug($"Received response '{ToString(response)}'."); + } + return isAvailable; } catch (Exception e) @@ -180,7 +191,7 @@ namespace SafeExamBrowser.Configuration.DataResources private string ToString(HttpResponseMessage response) { - return $"{(int)response.StatusCode} - {response.ReasonPhrase}"; + return $"{(int) response.StatusCode} - {response.ReasonPhrase}"; } } }