From 3a826519fe5c0326068160103d904cb0faa990dd Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 29 Jul 2023 20:35:36 +0100 Subject: [PATCH] Miscellaneous HTTP/task improvements --- Bloxstrap/App.xaml.cs | 12 +++++++----- Bloxstrap/HttpClientLoggingHandler.cs | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index bf958dd..4d04507 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -41,7 +41,11 @@ namespace Bloxstrap public static readonly JsonManager State = new(); public static readonly FastFlagManager FastFlags = new(); - public static readonly HttpClient HttpClient = new(new HttpClientLoggingHandler(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All })); + public static readonly HttpClient HttpClient = new( + new HttpClientLoggingHandler( + new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All } + ) + ); public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS) { @@ -107,7 +111,7 @@ namespace Bloxstrap LaunchArgs = e.Args; - HttpClient.Timeout = TimeSpan.FromMinutes(5); + HttpClient.Timeout = TimeSpan.FromSeconds(30); HttpClient.DefaultRequestHeaders.Add("User-Agent", ProjectRepository); if (LaunchArgs.Length > 0) @@ -295,9 +299,7 @@ namespace Bloxstrap } } - Task bootstrapperTask = Task.Run(() => bootstrapper.Run()); - - bootstrapperTask.ContinueWith(t => + Task bootstrapperTask = Task.Run(() => bootstrapper.Run()).ContinueWith(t => { Logger.WriteLine(LOG_IDENT, "Bootstrapper task has finished"); diff --git a/Bloxstrap/HttpClientLoggingHandler.cs b/Bloxstrap/HttpClientLoggingHandler.cs index 07cdacd..3eb830b 100644 --- a/Bloxstrap/HttpClientLoggingHandler.cs +++ b/Bloxstrap/HttpClientLoggingHandler.cs @@ -9,13 +9,13 @@ protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken) { - App.Logger.WriteLine("HttpClientLoggingHandler::HttpRequestMessage", $"{request.Method} {request.RequestUri}"); + App.Logger.WriteLine("HttpClientLoggingHandler::ProcessRequest", $"{request.Method} {request.RequestUri}"); return request; } protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellationToken) { - App.Logger.WriteLine("HttpClientLoggingHandler::HttpResponseMessage", $"{(int)response.StatusCode} {response.ReasonPhrase} {response.RequestMessage!.RequestUri}"); + App.Logger.WriteLine("HttpClientLoggingHandler::ProcessResponse", $"{(int)response.StatusCode} {response.ReasonPhrase} {response.RequestMessage!.RequestUri}"); return response; } }