From ecc1b844b1d6d6c0b03424e5018dedbdeee3911f Mon Sep 17 00:00:00 2001 From: Slendy Date: Thu, 30 Mar 2023 00:16:20 -0500 Subject: [PATCH] Add logging for empty request body bug --- ProjectLighthouse/Extensions/ControllerExtensions.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Extensions/ControllerExtensions.cs b/ProjectLighthouse/Extensions/ControllerExtensions.cs index f2cebb79..dbcda725 100644 --- a/ProjectLighthouse/Extensions/ControllerExtensions.cs +++ b/ProjectLighthouse/Extensions/ControllerExtensions.cs @@ -39,6 +39,7 @@ public static partial class ControllerExtensions public static async Task ReadBodyAsync(this ControllerBase controller) { + controller.Request.Body.Position = 0; StringBuilder builder = new(); while (true) @@ -78,6 +79,14 @@ public static partial class ControllerExtensions } } + string finalString = builder.ToString(); + if (finalString.Length != controller.Request.ContentLength) + { + Logger.Warn($"Failed to read entire body, contentType={controller.Request.ContentType}, " + + $"contentLen={controller.Request.ContentLength}, readLen={finalString.Length}", + LogArea.HTTP); + } + return builder.ToString(); } @@ -86,7 +95,6 @@ public static partial class ControllerExtensions public static async Task DeserializeBody(this ControllerBase controller, params string[] rootElements) { - controller.Request.Body.Position = 0; string bodyString = await controller.ReadBodyAsync(); try {