From 4335d132367baf2da588a2d6bd739acc845d1fb3 Mon Sep 17 00:00:00 2001 From: "Scott Beddall (from Dev Box)" Date: Tue, 18 Jun 2024 13:37:13 -0700 Subject: [PATCH] we need the manifest types to be ENTIRELY static --- .../Common/ContentTypeUtilities.cs | 14 +++++++++++--- .../Common/RecordEntry.cs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/ContentTypeUtilities.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/ContentTypeUtilities.cs index 0eb54dcd809..8a23a3f4b32 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/ContentTypeUtilities.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/ContentTypeUtilities.cs @@ -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="; @@ -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) { @@ -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; diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordEntry.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordEntry.cs index 8e35ee47974..235780323c0 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordEntry.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordEntry.cs @@ -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 {