mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Remove second HttpClient from PluginRepository (#1551)
Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
This commit is contained in:
parent
a71cb81384
commit
13346b04db
1 changed files with 19 additions and 2 deletions
|
|
@ -6,12 +6,14 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dalamud.Logging.Internal;
|
||||
using Dalamud.Networking.Http;
|
||||
using Dalamud.Plugin.Internal.Types.Manifest;
|
||||
using Dalamud.Utility;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Plugin.Internal.Types;
|
||||
|
|
@ -26,8 +28,9 @@ internal class PluginRepository
|
|||
/// </summary>
|
||||
public const string MainRepoUrl = "https://kamori.goats.dev/Plugin/PluginMaster";
|
||||
|
||||
private static readonly ModuleLog Log = new("PLUGINR");
|
||||
private const int HttpRequestTimeoutSeconds = 20;
|
||||
|
||||
private static readonly ModuleLog Log = new("PLUGINR");
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -112,7 +115,8 @@ internal class PluginRepository
|
|||
{
|
||||
Log.Information($"Fetching repo: {this.PluginMasterUrl}");
|
||||
|
||||
using var response = await this.httpClient.GetAsync(this.PluginMasterUrl);
|
||||
using var response = await this.GetPluginMaster(this.PluginMasterUrl);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var data = await response.Content.ReadAsStringAsync();
|
||||
|
|
@ -204,4 +208,17 @@ internal class PluginRepository
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> GetPluginMaster(string url, int timeout = HttpRequestTimeoutSeconds)
|
||||
{
|
||||
var httpClient = Service<HappyHttpClient>.Get().SharedHttpClient;
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true };
|
||||
|
||||
using var requestCts = new CancellationTokenSource(TimeSpan.FromSeconds(timeout));
|
||||
|
||||
return await httpClient.SendAsync(request, requestCts.Token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue