mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-27 02:53:04 +00:00
Refactor part 1
Cache httpClient and remove ConstructHttpClient()
This commit is contained in:
parent
8884d1fd73
commit
d901463ffb
1 changed files with 12 additions and 5 deletions
|
@ -95,10 +95,9 @@ namespace Ryujinx.Modules
|
||||||
// Get latest version number from GitHub API
|
// Get latest version number from GitHub API
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using HttpClient jsonClient = ConstructHttpClient();
|
|
||||||
|
|
||||||
string buildInfoUrl = $"{GitHubApiUrl}/repos/{ReleaseInformation.ReleaseChannelOwner}/{ReleaseInformation.ReleaseChannelRepo}/releases/latest";
|
string buildInfoUrl = $"{GitHubApiUrl}/repos/{ReleaseInformation.ReleaseChannelOwner}/{ReleaseInformation.ReleaseChannelRepo}/releases/latest";
|
||||||
string fetchedJson = await jsonClient.GetStringAsync(buildInfoUrl);
|
string fetchedJson = await httpClient.GetStringAsync(buildInfoUrl);
|
||||||
var fetched = JsonHelper.Deserialize(fetchedJson, _serializerContext.GithubReleasesJsonResponse);
|
var fetched = JsonHelper.Deserialize(fetchedJson, _serializerContext.GithubReleasesJsonResponse);
|
||||||
_buildVer = fetched.Name;
|
_buildVer = fetched.Name;
|
||||||
|
|
||||||
|
@ -185,12 +184,11 @@ namespace Ryujinx.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch build size information to learn chunk sizes.
|
// Fetch build size information to learn chunk sizes.
|
||||||
using HttpClient buildSizeClient = ConstructHttpClient();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
buildSizeClient.DefaultRequestHeaders.Add("Range", "bytes=0-0");
|
httpClient.DefaultRequestHeaders.Add("Range", "bytes=0-0");
|
||||||
|
|
||||||
HttpResponseMessage message = await buildSizeClient.GetAsync(new Uri(_buildUrl), HttpCompletionOption.ResponseHeadersRead);
|
HttpResponseMessage message = await httpClient.GetAsync(new Uri(_buildUrl), HttpCompletionOption.ResponseHeadersRead);
|
||||||
|
|
||||||
_buildSize = message.Content.Headers.ContentRange.Length.Value;
|
_buildSize = message.Content.Headers.ContentRange.Length.Value;
|
||||||
}
|
}
|
||||||
|
@ -221,6 +219,15 @@ namespace Ryujinx.Modules
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly HttpClient httpClient = new HttpClient
|
||||||
|
{
|
||||||
|
// Required by GitHub to interact with APIs.
|
||||||
|
DefaultRequestHeaders =
|
||||||
|
{
|
||||||
|
{ "User-Agent", "Ryujinx-Updater/1.0.0" }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static HttpClient ConstructHttpClient()
|
private static HttpClient ConstructHttpClient()
|
||||||
{
|
{
|
||||||
HttpClient result = new();
|
HttpClient result = new();
|
||||||
|
|
Loading…
Reference in a new issue