in src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Extensions/ContentTypeExtensions.cs [37:73]
public static bool IsJson(this ContentType contentType)
{
if (contentType == null)
{
return false;
}
string acceptedMainType = "application";
string acceptedSubType = "json";
ReadOnlySpan<char> mediaTypeSpan = contentType.MediaType.AsSpan();
// Since contentType has been validated using System.Net.Mime.ContentType,
// mediaType will always have exactly 2 parts after splitting on '/'
int slashIndex = mediaTypeSpan.IndexOf('/');
if (mediaTypeSpan.Slice(0, slashIndex).Equals(acceptedMainType.AsSpan(), StringComparison.OrdinalIgnoreCase))
{
ReadOnlySpan<char> subTypeSpan = mediaTypeSpan.Slice(slashIndex + 1);
while (!subTypeSpan.IsEmpty)
{
int plusIndex = subTypeSpan.IndexOf('+');
ReadOnlySpan<char> currentSubType = plusIndex == -1 ? subTypeSpan : subTypeSpan.Slice(0, plusIndex);
if (currentSubType.Equals(acceptedSubType.AsSpan(), StringComparison.OrdinalIgnoreCase))
{
return true;
}
subTypeSpan = plusIndex == -1 ? ReadOnlySpan<char>.Empty : subTypeSpan.Slice(plusIndex + 1);
}
}
return false;
}