reuse one httpclient across entire plugin
This commit is contained in:
@@ -26,6 +26,7 @@ using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
@@ -40,6 +41,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
private readonly MareConfigService _configService;
|
||||
private readonly ConcurrentDictionary<GameObjectHandler, Dictionary<string, FileDownloadStatus>> _currentDownloads = new();
|
||||
private readonly DalamudUtilService _dalamudUtilService;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly FileCacheManager _fileCacheManager;
|
||||
private readonly FileCompactor _fileCompactor;
|
||||
private readonly FileUploadManager _fileTransferManager;
|
||||
@@ -78,7 +80,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
FileCacheManager fileCacheManager,
|
||||
FileCompactor fileCompactor, ApiController apiController,
|
||||
IpcManager ipcManager, CacheMonitor cacheMonitor,
|
||||
DalamudUtilService dalamudUtilService) : base(logger, mediator, "Mare Synchronos Settings", performanceCollector)
|
||||
DalamudUtilService dalamudUtilService, HttpClient httpClient) : base(logger, mediator, "Mare Synchronos Settings", performanceCollector)
|
||||
{
|
||||
_configService = configService;
|
||||
_mareCharaFileManager = mareCharaFileManager;
|
||||
@@ -93,6 +95,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
_ipcManager = ipcManager;
|
||||
_cacheMonitor = cacheMonitor;
|
||||
_dalamudUtilService = dalamudUtilService;
|
||||
_httpClient = httpClient;
|
||||
_fileCompactor = fileCompactor;
|
||||
_uiShared = uiShared;
|
||||
AllowClickthrough = false;
|
||||
@@ -1833,13 +1836,14 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
return (false, false, $"Failed to convert {failedConversions.Count} entries: " + string.Join(", ", failedConversions.Select(k => k.CharacterName)));
|
||||
}
|
||||
|
||||
using HttpClient client = new();
|
||||
var baseUri = serverStorage.ServerUri.Replace("wss://", "https://").Replace("ws://", "http://");
|
||||
var oauthCheckUri = MareAuth.GetUIDsBasedOnSecretKeyFullPath(new Uri(baseUri));
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", serverStorage.OAuthToken);
|
||||
|
||||
var requestContent = JsonContent.Create(secretKeyMapping.Select(k => k.Key).ToList());
|
||||
using var response = await client.PostAsync(oauthCheckUri, requestContent, token).ConfigureAwait(false);
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Post, oauthCheckUri);
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", serverStorage.OAuthToken);
|
||||
requestMessage.Content = requestContent;
|
||||
|
||||
using var response = await _httpClient.SendAsync(requestMessage, token).ConfigureAwait(false);
|
||||
Dictionary<string, string>? secretKeyUidMapping = await JsonSerializer.DeserializeAsync<Dictionary<string, string>>
|
||||
(await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false), cancellationToken: token).ConfigureAwait(false);
|
||||
if (secretKeyUidMapping == null)
|
||||
|
||||
Reference in New Issue
Block a user