Skip to content

Commit

Permalink
we need the manifest types to be ENTIRELY static
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd committed Jun 18, 2024
1 parent 8911e03 commit 4335d13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@

using System;
using System.Text;
using Microsoft.AspNetCore.Razor.Language.Intermediate;

namespace Azure.Sdk.Tools.TestProxy.Common
{
internal static class ContentTypeUtilities
{

public static bool IsManifestContentType(string contentType)
{
const string dockerManifest = "application/vnd.docker.distribution.manifest.v";
const string dockerIndex = "application/vnd.oci.image.index.v";

return contentType.Contains(dockerManifest) || contentType.Contains(dockerIndex);
}

public static bool TryGetTextEncoding(string contentType, out Encoding encoding)
{
const string charsetMarker = "; charset=";
Expand All @@ -22,8 +32,6 @@ public static bool TryGetTextEncoding(string contentType, out Encoding encoding)

// Default is technically US-ASCII, but will default to UTF-8 which is a superset.
const string appFormUrlEncoded = "application/x-www-form-urlencoded";
const string dockerManifest = "application/vnd.docker.distribution.manifest.v";
const string dockerIndex = "application/vnd.oci.image.index.v";

if (contentType == null)
{
Expand All @@ -50,7 +58,7 @@ public static bool TryGetTextEncoding(string contentType, out Encoding encoding)
contentType.EndsWith(urlEncodedSuffix, StringComparison.OrdinalIgnoreCase) ||
contentType.StartsWith(appJsonPrefix, StringComparison.OrdinalIgnoreCase) ||
contentType.StartsWith(appFormUrlEncoded, StringComparison.OrdinalIgnoreCase)
) && !contentType.Contains(dockerManifest) && !contentType.Contains(dockerIndex)
) && !ContentTypeUtilities.IsManifestContentType(contentType)
)
{
encoding = Encoding.UTF8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void DeserializeBody(RequestOrResponse requestOrResponse, in Json

public static void NormalizeJsonBody(RequestOrResponse requestOrResponse)
{
if (requestOrResponse.TryGetContentType(out string contentType) && contentType.Contains("json"))
if (requestOrResponse.TryGetContentType(out string contentType) && contentType.Contains("json") && !ContentTypeUtilities.IsManifestContentType(contentType))
{
try
{
Expand Down

0 comments on commit 4335d13

Please sign in to comment.