From 4aa856f98a9c56e313b00ec6e47d377a1e1ddb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Wed, 22 Mar 2023 17:09:57 +0100 Subject: [PATCH] SEBWIN-645, SEBWIN-663: Reverted to informational build version for user agent of network resource requests. --- .../DataResources/NetworkResourceLoader.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs b/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs index f9ef3c9d..86f32290 100644 --- a/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs +++ b/SafeExamBrowser.Configuration/DataResources/NetworkResourceLoader.cs @@ -11,7 +11,6 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Net.Mime; using System.Threading.Tasks; using SafeExamBrowser.Configuration.Contracts; @@ -90,9 +89,12 @@ namespace SafeExamBrowser.Configuration.DataResources private HttpRequestMessage Build(HttpMethod method, Uri uri) { var request = new HttpRequestMessage(method, uri); - var userAgent = new ProductInfoHeaderValue("SEB", appConfig.ProgramBuildVersion); + var success = request.Headers.TryAddWithoutValidation("User-Agent", $"SEB/{appConfig.ProgramInformationalVersion}"); - request.Headers.UserAgent.Add(userAgent); + if (!success) + { + logger.Warn("Failed to add user agent header to request!"); + } return request; } @@ -145,7 +147,7 @@ namespace SafeExamBrowser.Configuration.DataResources private LoadStatus HandleBrowserResource(HttpResponseMessage response, out Stream data) { - data = default(Stream); + data = default; logger.Debug($"The {(IsUnauthorized(response) ? "resource needs authentication" : " response data is HTML")}.");