diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs index c6cec88193..73cc726ad8 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs @@ -5,6 +5,7 @@ using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public static partial class HttpUtilities @@ -19,13 +20,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure private readonly static ulong _httpOptionsMethodLong = GetAsciiStringAsLong("OPTIONS "); private readonly static ulong _httpTraceMethodLong = GetAsciiStringAsLong("TRACE \0\0"); - private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }); - private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }); - private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 }); - private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 }); - private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }); + private readonly static ulong _mask8Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - private readonly static Tuple[] _knownMethods = new Tuple[17]; + private readonly static ulong _mask7Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}); + + private readonly static ulong _mask6Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00}); + + private readonly static ulong _mask5Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00}); + + private readonly static ulong _mask4Chars = GetMaskAsLong(new byte[] + {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00}); + + private readonly static Tuple[] _knownMethods = + new Tuple[17]; private readonly static string[] _methodNames = new string[9]; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs index 3fa3d89026..b3575f6f5e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/GeneratedCodeTests.cs @@ -15,27 +15,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { const string frameHeadersGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs"; const string frameGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.Generated.cs"; - + const string httpUtilitiesGeneratedPath = "../../../../../src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/HttpUtilities.Generated.cs"; var testFrameHeadersGeneratedPath = Path.GetTempFileName(); var testFrameGeneratedPath = Path.GetTempFileName(); - + var testHttpUtilitiesGeneratedPath = Path.GetTempFileName(); try { var currentFrameHeadersGenerated = File.ReadAllText(frameHeadersGeneratedPath); var currentFrameGenerated = File.ReadAllText(frameGeneratedPath); + var currentHttpUtilitiesGenerated = File.ReadAllText(httpUtilitiesGeneratedPath); - CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath); + CodeGenerator.Program.Run(testFrameHeadersGeneratedPath, testFrameGeneratedPath, testHttpUtilitiesGeneratedPath); var testFrameHeadersGenerated = File.ReadAllText(testFrameHeadersGeneratedPath); var testFrameGenerated = File.ReadAllText(testFrameGeneratedPath); + var testHttpUtilitiesGenerated = File.ReadAllText(testHttpUtilitiesGeneratedPath); Assert.Equal(currentFrameHeadersGenerated, testFrameHeadersGenerated, ignoreLineEndingDifferences: true); Assert.Equal(currentFrameGenerated, testFrameGenerated, ignoreLineEndingDifferences: true); + Assert.Equal(currentHttpUtilitiesGenerated, testHttpUtilitiesGenerated, ignoreLineEndingDifferences: true); + } finally { File.Delete(testFrameHeadersGeneratedPath); File.Delete(testFrameGeneratedPath); + File.Delete(testHttpUtilitiesGeneratedPath); } } } diff --git a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs index 2c674fc71b..ddc0c62753 100644 --- a/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs +++ b/tools/CodeGenerator/HttpUtilities/HttpUtilities.cs @@ -67,6 +67,7 @@ using System; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; + namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure {{ public static partial class HttpUtilities @@ -75,8 +76,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure {0} {1} - - private readonly static Tuple[] _knownMethods = new Tuple[{2}]; + private readonly static Tuple[] _knownMethods = + new Tuple[{2}]; private readonly static string[] _methodNames = new string[{3}]; @@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var methodInfo = methodsInfo[index]; var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); - result.AppendFormat("\t\tprivate readonly static ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); + result.AppendFormat(" private readonly static ulong {0} = GetAsciiStringAsLong(\"{1}\");", httpMethodFieldName, methodInfo.MethodAsciiString.Replace("\0", "\\0")); if (index < methodsInfo.Count - 1) { @@ -132,8 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var hexMaskString = HttpUtilitiesGeneratorHelpers.GeHexString(maskArray, "0x", ", "); var maskFieldName = GetMaskFieldName(maskBytesLength); - result.AppendFormat("\t\tprivate readonly static ulong {0} = GetMaskAsLong(new byte[] {{ {1} }});", maskFieldName, hexMaskString); - + result.AppendFormat(" private readonly static ulong {0} = GetMaskAsLong(new byte[]\r\n {{{1}}});", maskFieldName, hexMaskString); + result.AppendLine(); if (index < distinctLengths.Count - 1) { result.AppendLine(); @@ -157,7 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure var maskFieldName = GetMaskFieldName(methodInfo.MaskLength); var httpMethodFieldName = GetHttpMethodFieldName(methodInfo); - result.AppendFormat("\t\t\tSetKnownMethod({0}, {1}, {2}.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(HttpMethod).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); + result.AppendFormat(" SetKnownMethod({0}, {1}, {2}.{3}, {4});", maskFieldName, httpMethodFieldName, typeof(HttpMethod).Name, methodInfo.HttpMethod, methodInfo.MaskLength - 1); if (index < methodsInfo.Count - 1) { @@ -180,7 +181,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { var methodInfo = methodsInfo[index]; - result.AppendFormat("\t\t\t_methodNames[(byte){0}.{1}] = {2}.{3};", typeof(HttpMethod).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); + result.AppendFormat(" _methodNames[(byte){0}.{1}] = {2}.{3};", typeof(HttpMethod).Name, methodInfo.HttpMethod, typeof(HttpMethods).Name, methodInfo.HttpMethod); if (index < methodsInfo.Count - 1) { @@ -218,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure string returnString = string.Format("return ({0}) & {1};", tmpReturn, HttpUtilitiesGeneratorHelpers.MaskToHexString(mask2)); - bodyString = string.Format("const int magicNumer = {0};\r\n\t\t\tvar tmp = (int)value & magicNumer;\r\n\t\t\t{1}", HttpUtilitiesGeneratorHelpers.MaskToHexString(mask), returnString); + bodyString = string.Format(" const int magicNumer = {0};\r\n var tmp = (int)value & magicNumer;\r\n {1}", HttpUtilitiesGeneratorHelpers.MaskToHexString(mask), returnString); } else