Add logging for empty request body bug

This commit is contained in:
Slendy 2023-03-30 00:16:20 -05:00
parent ff470bcb34
commit ecc1b844b1
No known key found for this signature in database
GPG key ID: 7288D68361B91428

View file

@ -39,6 +39,7 @@ public static partial class ControllerExtensions
public static async Task<string> 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<T?> DeserializeBody<T>(this ControllerBase controller, params string[] rootElements)
{
controller.Request.Body.Position = 0;
string bodyString = await controller.ReadBodyAsync();
try
{