2
0
Glax 2024-01-31 18:46:37 +01:00
parent 3c4867a276
commit 2dd82aad13
3 changed files with 14 additions and 8 deletions

View File

@ -14,10 +14,7 @@ internal class HttpDownloadClient : DownloadClient
public HttpDownloadClient(GlobalBase clone, Dictionary<byte, int> rateLimitRequestsPerMinute) : base(clone, rateLimitRequestsPerMinute)
{
if (settings.customUserAgent is null || settings.customUserAgent.Length < 1)
Client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Tranga", "1.0"));
else
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", settings.customUserAgent);
Client.DefaultRequestHeaders.UserAgent.Add(settings.userAgent);
}
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)

View File

@ -200,6 +200,9 @@ public class Server : GlobalBase
case "Settings":
SendResponse(HttpStatusCode.OK, response, settings);
break;
case "Settings/userAgent":
SendResponse(HttpStatusCode.OK, response, settings.userAgent);
break;
case "NotificationConnectors":
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
break;
@ -384,13 +387,13 @@ public class Server : GlobalBase
settings.UpdateWorkingDirectory(workingDirectory);
SendResponse(HttpStatusCode.Accepted, response);
break;*/
case "Settings/customUserAgent":
case "Settings/userAgent":
if(!requestVariables.TryGetValue("userAgent", out string? customUserAgent))
{
SendResponse(HttpStatusCode.BadRequest, response);
break;
}
settings.customUserAgent = customUserAgent;
settings.UpdateUserAgent(customUserAgent);
SendResponse(HttpStatusCode.Accepted, response);
break;
case "Settings/customRequestLimit":

View File

@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using Tranga.LibraryConnectors;
using Tranga.NotificationConnectors;
@ -12,7 +13,7 @@ public class TrangaSettings
public string workingDirectory { get; private set; }
public int apiPortNumber { get; init; }
public string styleSheet { get; private set; }
public string? customUserAgent { get; set; } = null;
public ProductInfoHeaderValue userAgent { get; set; } = new ("Tranga", "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");
@ -120,6 +121,11 @@ public class TrangaSettings
ExportSettings();
}
public void UpdateUserAgent(string customUserAgent)
{
this.userAgent = new ProductInfoHeaderValue(ProductHeaderValue.Parse(customUserAgent));
}
public void ExportSettings()
{
if (File.Exists(settingsFilePath))