Skip to content

Commit

Permalink
Update HttpClient user agent format
Browse files Browse the repository at this point in the history
TIL user agents have a specific syntax lol
  • Loading branch information
pizzaboxer committed Sep 30, 2024
1 parent 43ab562 commit 84da94c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 13 additions & 1 deletion Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,22 @@ protected override void OnStartup(StartupEventArgs e)

Logger.WriteLine(LOG_IDENT, $"Starting {ProjectName} v{Version}");

string userAgent = $"{ProjectName}/{Version}";

if (IsActionBuild)
{
Logger.WriteLine(LOG_IDENT, $"Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from commit {BuildMetadata.CommitHash} ({BuildMetadata.CommitRef})");

if (IsProductionBuild)
userAgent += $" (Production)";
else
userAgent += $" (Artifact {BuildMetadata.CommitHash}, {BuildMetadata.CommitRef})";
}
else
{
Logger.WriteLine(LOG_IDENT, $"Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from {BuildMetadata.Machine}");
userAgent += $" (Build {BuildMetadata.Machine})";
}

Logger.WriteLine(LOG_IDENT, $"Loaded from {Paths.Process}");

Expand All @@ -153,7 +165,7 @@ protected override void OnStartup(StartupEventArgs e)
ApplicationConfiguration.Initialize();

HttpClient.Timeout = TimeSpan.FromSeconds(30);
HttpClient.DefaultRequestHeaders.Add("User-Agent", ProjectRepository);
HttpClient.DefaultRequestHeaders.Add("User-Agent", userAgent);

LaunchSettings = new LaunchSettings(e.Args);

Expand Down
4 changes: 2 additions & 2 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ private async Task DownloadPackage(Package package)

if (ex.GetType() == typeof(ChecksumFailedException))
{
_ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value=httpFail");
_ = App.HttpClient.GetAsync($"https://bloxstraplabs.com/metrics/post?key=packageDownloadState&value=httpFail");

Frontend.ShowConnectivityDialog(
Strings.Dialog_Connectivity_UnableToDownload,
Expand Down Expand Up @@ -1044,7 +1044,7 @@ private async Task DownloadPackage(Package package)
if (statIsRetrying)
{
string stat = statIsHttp ? "httpSuccess" : "retrySuccess";
_ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value={stat}");
_ = App.HttpClient.GetAsync($"https://bloxstraplabs.com/metrics/post?key=packageDownloadState&value={stat}");
}
}

Expand Down
2 changes: 0 additions & 2 deletions Bloxstrap/GlobalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
public static class GlobalCache
{
public static readonly Dictionary<string, string?> ServerLocation = new();

public static readonly Dictionary<long, ThumbnailResponse> UserThumbnails = new();
}
}

0 comments on commit 84da94c

Please sign in to comment.