reuse httpclient

This commit is contained in:
Matthew Brown 2022-11-12 22:50:27 +00:00
parent 01a9cff6e1
commit 5fdb341918
5 changed files with 22 additions and 30 deletions

View File

@ -66,7 +66,7 @@ namespace Bloxstrap
"By default, two mod presets are provided for restoring the old death\n" +
"sound and the old mouse cursor.\n";
private static readonly HttpClient Client = new();
public static readonly HttpClient Client = new();
private string? LaunchCommandLine;

View File

@ -102,9 +102,7 @@ namespace Bloxstrap.Helpers
string baseUrl = BuildBaseUrl(channel);
string lastDeploy = "";
using (HttpClient client = new())
{
string deployHistory = await client.GetStringAsync($"{baseUrl}/DeployHistory.txt");
string deployHistory = await Bootstrapper.Client.GetStringAsync($"{baseUrl}/DeployHistory.txt");
using (StringReader reader = new(deployHistory))
{
@ -116,7 +114,6 @@ namespace Bloxstrap.Helpers
lastDeploy = line;
}
}
}
if (String.IsNullOrEmpty(lastDeploy))
throw new Exception($"Could not get latest deploy for channel {channel}");

View File

@ -97,16 +97,13 @@ namespace Bloxstrap.Helpers.Integrations
Debug.WriteLine("Installing/Updating rbxfpsunlocker...");
using (HttpClient client = new())
{
byte[] bytes = await client.GetByteArrayAsync(downloadUrl);
byte[] bytes = await Bootstrapper.Client.GetByteArrayAsync(downloadUrl);
using (MemoryStream zipStream = new(bytes))
{
ZipArchive zip = new(zipStream);
zip.ExtractToDirectory(folderLocation, true);
}
}
if (!File.Exists(settingsLocation))
{

View File

@ -75,11 +75,8 @@ namespace Bloxstrap.Helpers.RSMM
string pkgManifestUrl = $"{DeployManager.BaseUrl}/{versionGuid}-rbxPkgManifest.txt";
string pkgManifestData;
using (HttpClient http = new())
{
var getData = http.GetStringAsync(pkgManifestUrl);
var getData = Bootstrapper.Client.GetStringAsync(pkgManifestUrl);
pkgManifestData = await getData.ConfigureAwait(false);
}
return new PackageManifest(pkgManifestData);
}

View File

@ -15,13 +15,14 @@ namespace Bloxstrap.Helpers
public static async Task<T?> GetJson<T>(string url)
{
using (HttpClient client = new())
var request = await Bootstrapper.Client.SendAsync(new()
{
client.DefaultRequestHeaders.Add("User-Agent", Program.ProjectRepository);
string json = await client.GetStringAsync(url);
return JsonSerializer.Deserialize<T>(json);
Headers = {
{ "User-Agent", Program.ProjectRepository }
}
});
var json = await request.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<T>(json);
}
public static string MD5File(string filename)