add mare version to http client headers

This commit is contained in:
rootdarkarchon
2023-04-11 13:54:42 +02:00
parent 4b278bd456
commit d5f140a142
2 changed files with 7 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ using MareSynchronos.WebAPI.Files.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Reflection;
namespace MareSynchronos.WebAPI.Files; namespace MareSynchronos.WebAPI.Files;
@@ -23,6 +24,8 @@ public class FileTransferOrchestrator : DisposableMediatorSubscriberBase
_serverManager = serverManager; _serverManager = serverManager;
_httpClient = new(); _httpClient = new();
_httpClient.Timeout = TimeSpan.FromSeconds(300); _httpClient.Timeout = TimeSpan.FromSeconds(300);
var ver = Assembly.GetExecutingAssembly().GetName().Version;
_httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MareSynchronos", ver!.Major + "." + ver!.Minor + "." + ver!.Build));
_availableDownloadSlots = mareConfig.Current.ParallelDownloads; _availableDownloadSlots = mareConfig.Current.ParallelDownloads;
_downloadSemaphore = new(_availableDownloadSlots); _downloadSemaphore = new(_availableDownloadSlots);

View File

@@ -14,6 +14,8 @@ using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.Services; using MareSynchronos.Services;
using MareSynchronos.API.Data.Extensions; using MareSynchronos.API.Data.Extensions;
using MareSynchronos.API.Data; using MareSynchronos.API.Data;
using System.Net.Http.Headers;
using System.Net.Http;
namespace MareSynchronos.WebAPI; namespace MareSynchronos.WebAPI;
@@ -138,6 +140,8 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
{ {
Logger.LogDebug("Requesting new JWT"); Logger.LogDebug("Requesting new JWT");
using HttpClient httpClient = new(); using HttpClient httpClient = new();
var ver = Assembly.GetExecutingAssembly().GetName().Version;
httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MareSynchronos", ver!.Major + "." + ver!.Minor + "." + ver!.Build));
var postUri = MareAuth.AuthFullPath(new Uri(_serverManager.CurrentApiUrl var postUri = MareAuth.AuthFullPath(new Uri(_serverManager.CurrentApiUrl
.Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase) .Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase)
.Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase))); .Replace("ws://", "http://", StringComparison.OrdinalIgnoreCase)));