Merge pull request #45 from bluepilledgreat/reuse-httpclient

reuse httpclient
This commit is contained in:
pizzaboxer 2022-11-14 17:15:51 +00:00 committed by GitHub
commit c6410eb407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 30 deletions

View File

@ -1,6 +1,7 @@
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Http;
using Microsoft.Win32;
@ -66,7 +67,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(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All });
private string? LaunchCommandLine;

View File

@ -104,9 +104,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))
{
@ -118,7 +116,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,15 @@ 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);
RequestUri = new Uri(url),
Headers = {
{ "User-Agent", Program.ProjectRepository }
}
});
var json = await request.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<T>(json);
}
public static string MD5File(string filename)