diff --git a/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs b/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs index ef5a7b191..9e4e1f7a0 100644 --- a/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs +++ b/src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs @@ -18,6 +18,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using System.Text; using Grpc.Core; @@ -108,7 +109,7 @@ public static byte[] ParseBinaryHeader(string base64) switch (base64.Length % 4) { case 0: - // base64 has the required padding + // base64 has the required padding decodable = base64; break; case 2: @@ -208,11 +209,8 @@ public static AuthContext CreateAuthContext(X509Certificate2 clientCertificate) static void AddProperty(Dictionary> properties, string name, string value) { - if (!properties.TryGetValue(name, out var values)) - { - values = new List(); - properties[name] = values; - } + ref var values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties, name, out _); + values ??= []; values.Add(AuthProperty.Create(name, Encoding.UTF8.GetBytes(value))); } diff --git a/src/Grpc.AspNetCore.Web/Internal/ServerGrpcWebMode.cs b/src/Grpc.AspNetCore.Web/Internal/ServerGrpcWebMode.cs index 2d7a74938..ce980264d 100644 --- a/src/Grpc.AspNetCore.Web/Internal/ServerGrpcWebMode.cs +++ b/src/Grpc.AspNetCore.Web/Internal/ServerGrpcWebMode.cs @@ -20,7 +20,7 @@ namespace Grpc.AspNetCore.Web.Internal; internal readonly record struct ServerGrpcWebContext(ServerGrpcWebMode Request, ServerGrpcWebMode Response); -internal enum ServerGrpcWebMode +internal enum ServerGrpcWebMode : byte { None, GrpcWeb, diff --git a/src/Shared/Server/MethodOptions.cs b/src/Shared/Server/MethodOptions.cs index 1f0e29c24..f50fc4cd3 100644 --- a/src/Shared/Server/MethodOptions.cs +++ b/src/Shared/Server/MethodOptions.cs @@ -158,10 +158,7 @@ private static void AddCompressionProviders(Dictionary