Skip to content

Commit f039dd4

Browse files
committed
fix(Updater::Download): Fix missing user agent for downloading release
1 parent 310d948 commit f039dd4

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Net.Http.Headers;
2+
using System.Windows.Forms;
3+
4+
namespace SoundSwitch.Framework.Updater
5+
{
6+
internal static class ApplicationInfo
7+
{
8+
public static readonly ProductInfoHeaderValue ProductValue = new ProductInfoHeaderValue(Application.ProductName, Application.ProductVersion);
9+
public static readonly ProductInfoHeaderValue CommentValue = new ProductInfoHeaderValue("(+https://soundwitch.aaflalo.me)");
10+
}
11+
}

SoundSwitch/Framework/Updater/FileDownloader.cs

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static async Task DownloadFileAsync(Uri uri, Stream toStream, Cancellatio
4949
else
5050
{
5151
using var client = new HttpClient();
52+
client.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.ProductValue);
53+
client.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.CommentValue);
5254
using var response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
5355

5456
if (progressCallback != null)

SoundSwitch/Framework/Updater/UpdateChecker.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public class UpdateChecker
3535

3636
private readonly Uri _releaseUrl;
3737
public EventHandler<NewReleaseEvent> UpdateAvailable;
38-
private static readonly ProductInfoHeaderValue ProductValue;
39-
private static readonly ProductInfoHeaderValue CommentValue;
4038
public bool Beta { get; set; }
4139

4240
public UpdateChecker(Uri releaseUrl) : this(releaseUrl, false)
@@ -49,12 +47,6 @@ public UpdateChecker(Uri releaseUrl, bool checkBeta)
4947
Beta = checkBeta;
5048
}
5149

52-
static UpdateChecker()
53-
{
54-
ProductValue = new ProductInfoHeaderValue(Application.ProductName, Application.ProductVersion);
55-
CommentValue = new ProductInfoHeaderValue("(+https://soundwitch.aaflalo.me)");
56-
}
57-
5850
private bool ProcessRelease(GitHubRelease serverRelease)
5951
{
6052
Log.Information("Checking version {version} ", serverRelease);
@@ -97,8 +89,8 @@ private bool ProcessRelease(GitHubRelease serverRelease)
9789
public async Task CheckForUpdate(CancellationToken token)
9890
{
9991
using var httpClient = new HttpClient(new SentryHttpMessageHandler());
100-
httpClient.DefaultRequestHeaders.UserAgent.Add(ProductValue);
101-
httpClient.DefaultRequestHeaders.UserAgent.Add(CommentValue);
92+
httpClient.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.ProductValue);
93+
httpClient.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.CommentValue);
10294
httpClient.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
10395
var releases = await httpClient.GetFromJsonAsync<GitHubRelease[]>(_releaseUrl, token);
10496
foreach (var release in releases ?? Array.Empty<GitHubRelease>())

0 commit comments

Comments
 (0)