diff --git a/src/Ryujinx/Modules/Updater/Updater.cs b/src/Ryujinx/Modules/Updater/Updater.cs index 9f186f2b3..e5eca0a7a 100644 --- a/src/Ryujinx/Modules/Updater/Updater.cs +++ b/src/Ryujinx/Modules/Updater/Updater.cs @@ -95,10 +95,9 @@ namespace Ryujinx.Modules // Get latest version number from GitHub API try { - using HttpClient jsonClient = ConstructHttpClient(); 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); _buildVer = fetched.Name; @@ -185,12 +184,11 @@ namespace Ryujinx.Modules } // Fetch build size information to learn chunk sizes. - using HttpClient buildSizeClient = ConstructHttpClient(); 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; } @@ -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() { HttpClient result = new();