Skip to content

Commit

Permalink
Add verbose HTTP logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Jul 2, 2023
1 parent dc0531e commit 9ea7900
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public partial class App : Application
public static bool IsMenuLaunch { get; private set; } = false;
public static string[] LaunchArgs { get; private set; } = null!;

public static BuildMetadataAttribute BuildMetadata => Assembly.GetExecutingAssembly().GetCustomAttribute<BuildMetadataAttribute>()!;
public static BuildMetadataAttribute BuildMetadata = Assembly.GetExecutingAssembly().GetCustomAttribute<BuildMetadataAttribute>()!;
public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2];

// singletons
public static readonly Logger Logger = new();
public static readonly HttpClient HttpClient = new(new HttpClientLoggingHandler(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }));

public static readonly JsonManager<Settings> Settings = new();
public static readonly JsonManager<State> State = new();
public static readonly FastFlagManager FastFlags = new();
public static readonly HttpClient HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All });

public static System.Windows.Forms.NotifyIcon Notification { get; private set; } = null!;

Expand Down
31 changes: 31 additions & 0 deletions Bloxstrap/HttpClientLoggingHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 0 additions & 2 deletions Bloxstrap/RobloxDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public static async Task<ClientVersion> GetInfo(string channel, bool timestamp =
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)!;

// for preferences
Expand Down
6 changes: 3 additions & 3 deletions Bloxstrap/UI/ExceptionDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
<Button x:Name="LocateLogFileButton" Content="Locate log file" />
<ComboBox x:Name="ReportOptions" SelectedIndex="0" Padding="12,6,12,6" Margin="12,0,0,0">
<ComboBoxItem Content="Report exception" Visibility="Collapsed" />
<ComboBoxItem Content="Report via GitHub" />
<ComboBoxItem Content="Report via Discord" />
<ComboBoxItem Content="Submit report..." Visibility="Collapsed" />
<ComboBoxItem Content="Submit report via GitHub" />
<ComboBoxItem Content="Submit report via Discord" />
</ComboBox>
<Button x:Name="CloseButton" MinWidth="100" Content="Close" Margin="12,0,0,0" />
</StackPanel>
Expand Down
11 changes: 6 additions & 5 deletions Bloxstrap/UI/ExceptionDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Media;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

using Bloxstrap.Utility;

Expand Down Expand Up @@ -60,6 +55,12 @@ public ExceptionDialog(Exception exception)
};

SystemSounds.Hand.Play();

Loaded += delegate
{
IntPtr hWnd = new WindowInteropHelper(this).Handle;
NativeMethods.FlashWindow(hWnd, true);
};
}
}
}
6 changes: 1 addition & 5 deletions Bloxstrap/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text.Json;
using System.Threading.Tasks;

Expand All @@ -27,14 +25,12 @@ public static long GetFreeDiskSpace(string path)
{
try
{
App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Getting JSON from {url}!");
string json = await App.HttpClient.GetStringAsync(url);
App.Logger.WriteLine($"[Utilities::GetJson<{typeof(T).Name}>] Got JSON: {json}");
return JsonSerializer.Deserialize<T>(json);
}
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}");
return default;
}
Expand Down

0 comments on commit 9ea7900

Please sign in to comment.