literally just logging

This commit is contained in:
2026-02-02 20:24:43 -05:00
parent 9fb86d3839
commit 8dbac23944
4 changed files with 65 additions and 33 deletions

View File

@@ -23,7 +23,7 @@ public class WebSocketProxyMiddleware
_settings = settings.Value;
_logger = logger;
_logger.LogInformation("🔧 WebSocketProxyMiddleware initialized - Jellyfin URL: {Url}", _settings.Url);
_logger.LogWarning("🔧 WEBSOCKET: WebSocketProxyMiddleware initialized - Jellyfin URL: {Url}", _settings.Url);
}
public async Task InvokeAsync(HttpContext context)
@@ -38,7 +38,7 @@ public class WebSocketProxyMiddleware
isWebSocket ||
context.Request.Headers.ContainsKey("Upgrade"))
{
_logger.LogInformation("🔍 Potential WebSocket request: Path={Path}, IsWs={IsWs}, Method={Method}, Upgrade={Upgrade}, Connection={Connection}",
_logger.LogWarning("🔍 WEBSOCKET: Potential WebSocket request: Path={Path}, IsWs={IsWs}, Method={Method}, Upgrade={Upgrade}, Connection={Connection}",
path,
isWebSocket,
context.Request.Method,
@@ -50,7 +50,7 @@ public class WebSocketProxyMiddleware
if (context.Request.Path.StartsWithSegments("/socket", StringComparison.OrdinalIgnoreCase) &&
context.WebSockets.IsWebSocketRequest)
{
_logger.LogInformation("🔌 WebSocket connection request received from {RemoteIp}",
_logger.LogWarning("🔌 WEBSOCKET: WebSocket connection request received from {RemoteIp}",
context.Connection.RemoteIpAddress);
await HandleWebSocketProxyAsync(context);
@@ -70,7 +70,7 @@ public class WebSocketProxyMiddleware
{
// Accept the WebSocket connection from the client
clientWebSocket = await context.WebSockets.AcceptWebSocketAsync();
_logger.LogInformation("✓ Client WebSocket accepted");
_logger.LogWarning("✓ WEBSOCKET: Client WebSocket accepted");
// Build Jellyfin WebSocket URL
var jellyfinUrl = _settings.Url?.TrimEnd('/') ?? "";
@@ -84,7 +84,7 @@ public class WebSocketProxyMiddleware
jellyfinWsUrl += context.Request.QueryString.Value;
}
_logger.LogInformation("Connecting to Jellyfin WebSocket: {Url}", jellyfinWsUrl);
_logger.LogWarning("🔗 WEBSOCKET: Connecting to Jellyfin WebSocket: {Url}", jellyfinWsUrl);
// Connect to Jellyfin WebSocket
serverWebSocket = new ClientWebSocket();
@@ -93,19 +93,19 @@ public class WebSocketProxyMiddleware
if (context.Request.Headers.TryGetValue("Authorization", out var authHeader))
{
serverWebSocket.Options.SetRequestHeader("Authorization", authHeader.ToString());
_logger.LogDebug("Forwarded Authorization header");
_logger.LogWarning("🔑 WEBSOCKET: Forwarded Authorization header");
}
else if (context.Request.Headers.TryGetValue("X-Emby-Authorization", out var embyAuthHeader))
{
serverWebSocket.Options.SetRequestHeader("X-Emby-Authorization", embyAuthHeader.ToString());
_logger.LogDebug("Forwarded X-Emby-Authorization header");
_logger.LogWarning("🔑 WEBSOCKET: Forwarded X-Emby-Authorization header");
}
// Set user agent
serverWebSocket.Options.SetRequestHeader("User-Agent", "Allstarr/1.0");
await serverWebSocket.ConnectAsync(new Uri(jellyfinWsUrl), context.RequestAborted);
_logger.LogInformation("✓ Connected to Jellyfin WebSocket");
_logger.LogWarning("✓ WEBSOCKET: Connected to Jellyfin WebSocket");
// Start bidirectional proxying
var clientToServer = ProxyMessagesAsync(clientWebSocket, serverWebSocket, "Client→Server", context.RequestAborted);
@@ -114,15 +114,15 @@ public class WebSocketProxyMiddleware
// Wait for either direction to complete
await Task.WhenAny(clientToServer, serverToClient);
_logger.LogInformation("WebSocket proxy connection closed");
_logger.LogWarning("🔌 WEBSOCKET: WebSocket proxy connection closed");
}
catch (WebSocketException wsEx)
{
_logger.LogWarning(wsEx, "WebSocket error: {Message}", wsEx.Message);
_logger.LogWarning(wsEx, "⚠️ WEBSOCKET: WebSocket error: {Message}", wsEx.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in WebSocket proxy");
_logger.LogError(ex, "❌ WEBSOCKET: Error in WebSocket proxy");
}
finally
{
@@ -154,7 +154,7 @@ public class WebSocketProxyMiddleware
clientWebSocket?.Dispose();
serverWebSocket?.Dispose();
_logger.LogInformation("WebSocket connections cleaned up");
_logger.LogWarning("🧹 WEBSOCKET: WebSocket connections cleaned up");
}
}
@@ -175,7 +175,7 @@ public class WebSocketProxyMiddleware
if (result.MessageType == WebSocketMessageType.Close)
{
_logger.LogInformation("{Direction}: Close message received", direction);
_logger.LogWarning("🔌 WEBSOCKET {Direction}: Close message received", direction);
await destination.CloseAsync(
result.CloseStatus ?? WebSocketCloseStatus.NormalClosure,
result.CloseStatusDescription,
@@ -215,15 +215,15 @@ public class WebSocketProxyMiddleware
}
catch (OperationCanceledException)
{
_logger.LogInformation("{Direction}: Operation cancelled", direction);
_logger.LogWarning("⚠️ WEBSOCKET {Direction}: Operation cancelled", direction);
}
catch (WebSocketException wsEx) when (wsEx.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
{
_logger.LogInformation("{Direction}: Connection closed prematurely", direction);
_logger.LogWarning("⚠️ WEBSOCKET {Direction}: Connection closed prematurely", direction);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "{Direction}: Error proxying messages", direction);
_logger.LogWarning(ex, "⚠️ WEBSOCKET {Direction}: Error proxying messages", direction);
}
}
}