Attempt to fix JSON parsing of text/plain content type (#1172)

* UseContentType

* Fix unit tests

* Add a unit test and an integration test for the fix.

* Simplify body type checking with GetBodyType extension.

* Split IBodyDataExtension, and use imperative style instead of functional style

* Remove excessive null forgiving operators

* Adjust braces

---------

Co-authored-by: Ruxo Zheng <rz@just.sent.as>
This commit is contained in:
Ruxo
2024-09-20 18:19:32 +07:00
committed by GitHub
parent 527278e60c
commit dd80fd7822
5 changed files with 174 additions and 17 deletions

View File

@@ -0,0 +1,20 @@
using WireMock.Types;
// ReSharper disable once CheckNamespace
namespace WireMock.Util;
public static class IBodyDataExtension
{
public static BodyType GetBodyType(this IBodyData bodyData)
{
if (bodyData.DetectedBodyTypeFromContentType is not null and not BodyType.None)
{
return bodyData.DetectedBodyTypeFromContentType.Value;
}
if (bodyData.DetectedBodyType is not null and not BodyType.None)
{
return bodyData.DetectedBodyType.Value;
}
return BodyType.None;
}
}