From 3ca6245fc2bdadddb51efcdc1d13c02c6535ff45 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 31 Jan 2024 19:00:38 +0100 Subject: [PATCH] safe Useragent as string and export settings after changing --- Tranga/MangaConnectors/HttpDownloadClient.cs | 2 +- Tranga/TrangaSettings.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Tranga/MangaConnectors/HttpDownloadClient.cs b/Tranga/MangaConnectors/HttpDownloadClient.cs index e2d9e3d..342b8a1 100644 --- a/Tranga/MangaConnectors/HttpDownloadClient.cs +++ b/Tranga/MangaConnectors/HttpDownloadClient.cs @@ -14,7 +14,7 @@ internal class HttpDownloadClient : DownloadClient public HttpDownloadClient(GlobalBase clone, Dictionary rateLimitRequestsPerMinute) : base(clone, rateLimitRequestsPerMinute) { - Client.DefaultRequestHeaders.UserAgent.Add(settings.userAgent); + Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", settings.userAgent); } protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null) diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index d9bffd3..a75c8dd 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -13,7 +13,9 @@ public class TrangaSettings public string workingDirectory { get; private set; } public int apiPortNumber { get; init; } public string styleSheet { get; private set; } - public ProductInfoHeaderValue userAgent { get; set; } = new ("Tranga", "1.0"); + + public string userAgent { get; set; } = + $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0"; [JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json"); [JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json"); [JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json"); @@ -123,7 +125,8 @@ public class TrangaSettings public void UpdateUserAgent(string customUserAgent) { - this.userAgent = new ProductInfoHeaderValue(ProductHeaderValue.Parse(customUserAgent)); + this.userAgent = customUserAgent; + ExportSettings(); } public void ExportSettings()