Add verbose HTTP logging (2.4.0 backport)

This commit is contained in:
pizzaboxer 2023-07-02 10:57:24 +01:00
parent cec5c58e7c
commit 69dc4f1c16
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
4 changed files with 35 additions and 7 deletions

View File

@ -46,11 +46,12 @@ namespace Bloxstrap
public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2];
// singletons // singletons
public static readonly Logger Logger = new();
public static readonly JsonManager<Settings> Settings = new(); public static readonly JsonManager<Settings> Settings = new();
public static readonly JsonManager<State> State = new(); public static readonly JsonManager<State> State = new();
public static readonly FastFlagManager FastFlags = new(); public static readonly FastFlagManager FastFlags = new();
public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All });
public static readonly Logger Logger = new();
public static readonly HttpClient HttpClient = new(new HttpClientLoggingHandler(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }));
public static System.Windows.Forms.NotifyIcon Notification { get; private set; } = null!; public static System.Windows.Forms.NotifyIcon Notification { get; private set; } = null!;

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Bloxstrap
{
internal class HttpClientLoggingHandler : MessageProcessingHandler
{
public HttpClientLoggingHandler(HttpMessageHandler innerHandler)
: base(innerHandler)
{
}
protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken)
{
App.Logger.WriteLine($"[HttpClientLoggingHandler::HttpRequestMessage] {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}");
return response;
}
}
}

View File

@ -110,8 +110,6 @@ namespace Bloxstrap
throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})"); throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})");
} }
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Got JSON: {rawResponse}");
ClientVersion clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!; ClientVersion clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!;
// for preferences // for preferences

View File

@ -49,14 +49,12 @@ namespace Bloxstrap
{ {
try try
{ {
App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Getting JSON from {url}!");
string json = await App.HttpClient.GetStringAsync(url); string json = await App.HttpClient.GetStringAsync(url);
App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Got JSON: {json}");
return JsonSerializer.Deserialize<T>(json); return JsonSerializer.Deserialize<T>(json);
} }
catch (Exception ex) catch (Exception ex)
{ {
App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Failed to deserialize JSON!"); App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Failed to deserialize JSON for {url}!");
App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] {ex}"); App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] {ex}");
return default; return default;
} }