ContentType "application/vnd.api+json" is not recognized as json (#186)

* Admin API GetRequestsAsync Json/JsonApi request body tests

* Fix code + update unit-tests
This commit is contained in:
Steve Land
2018-08-17 18:15:01 +01:00
committed by Stef Heyenrath
parent b57d118c3d
commit fb6b25a9c5
4 changed files with 168 additions and 69 deletions

View File

@@ -10,6 +10,12 @@ namespace WireMock.Util
{
internal static class BodyParser
{
private static readonly string[] JsonContentTypes =
{
"application/json",
"application/vnd.api+json"
};
private static readonly string[] TextContentTypes =
{
"text/",
@@ -41,7 +47,7 @@ namespace WireMock.Util
{
var data = new BodyData();
if (contentTypeHeaderValue != null && TextContentTypes.Any(t => contentTypeHeaderValue.StartsWith(t, StringComparison.OrdinalIgnoreCase)))
if (contentTypeHeaderValue != null && TextContentTypes.Any(text => contentTypeHeaderValue.StartsWith(text, StringComparison.OrdinalIgnoreCase)))
{
try
{
@@ -55,7 +61,7 @@ namespace WireMock.Util
data.BodyAsBytes = await ReadBytesAsync(stream);
}
}
else if (contentTypeHeaderValue != null && contentTypeHeaderValue.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
else if (contentTypeHeaderValue != null && JsonContentTypes.Any(json => contentTypeHeaderValue.StartsWith(json, StringComparison.OrdinalIgnoreCase)))
{
var stringData = await ReadStringAsync(stream);
data.BodyAsString = stringData.Item1;