From 920d93590d9136f54444c371c9a5cfadc4325927 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 21 Aug 2020 07:39:40 +1200 Subject: [PATCH] Remove HTTP/2 headers from request primary headers (#24900) --- .../Internal/Http/HttpHeaders.Generated.cs | 654 +++++++++--------- .../Kestrel/test/GeneratedCodeTests.cs | 36 +- src/Servers/Kestrel/shared/KnownHeaders.cs | 55 +- 3 files changed, 394 insertions(+), 351 deletions(-) diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs index d80fe0b84c..8e20658972 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs @@ -1208,15 +1208,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 5: { - if (ReferenceEquals(HeaderNames.Path, key)) - { - if ((_bits & 0x400000L) != 0) - { - value = _headers._Path; - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.Allow, key)) { if ((_bits & 0x800L) != 0) @@ -1226,6 +1217,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Path, key)) + { + if ((_bits & 0x400000L) != 0) + { + value = _headers._Path; + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.Range, key)) { if ((_bits & 0x80000000000L) != 0) @@ -1236,15 +1236,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return false; } - if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x400000L) != 0) - { - value = _headers._Path; - return true; - } - return false; - } if (HeaderNames.Allow.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x800L) != 0) @@ -1254,6 +1245,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x400000L) != 0) + { + value = _headers._Path; + return true; + } + return false; + } if (HeaderNames.Range.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x80000000000L) != 0) @@ -1362,24 +1362,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 7: { - if (ReferenceEquals(HeaderNames.Method, key)) - { - if ((_bits & 0x200000L) != 0) - { - value = _headers._Method; - return true; - } - return false; - } - if (ReferenceEquals(HeaderNames.Scheme, key)) - { - if ((_bits & 0x800000L) != 0) - { - value = _headers._Scheme; - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.Trailer, key)) { if ((_bits & 0x40L) != 0) @@ -1416,6 +1398,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Method, key)) + { + if ((_bits & 0x200000L) != 0) + { + value = _headers._Method; + return true; + } + return false; + } + if (ReferenceEquals(HeaderNames.Scheme, key)) + { + if ((_bits & 0x800000L) != 0) + { + value = _headers._Scheme; + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.Referer, key)) { if ((_bits & 0x40000000000L) != 0) @@ -1426,24 +1426,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return false; } - if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x200000L) != 0) - { - value = _headers._Method; - return true; - } - return false; - } - if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x800000L) != 0) - { - value = _headers._Scheme; - return true; - } - return false; - } if (HeaderNames.Trailer.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x40L) != 0) @@ -1480,6 +1462,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x200000L) != 0) + { + value = _headers._Method; + return true; + } + return false; + } + if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x800000L) != 0) + { + value = _headers._Scheme; + return true; + } + return false; + } if (HeaderNames.Referer.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x40000000000L) != 0) @@ -1566,15 +1566,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } - if (ReferenceEquals(HeaderNames.Authority, key)) - { - if ((_bits & 0x100000L) != 0) - { - value = _headers._Authority; - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.UserAgent, key)) { if ((_bits & 0x400000000000L) != 0) @@ -1593,6 +1584,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Authority, key)) + { + if ((_bits & 0x100000L) != 0) + { + value = _headers._Authority; + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.RequestId, key)) { if ((_bits & 0x2000000000000L) != 0) @@ -1621,15 +1621,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } - if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x100000L) != 0) - { - value = _headers._Authority; - return true; - } - return false; - } if (HeaderNames.UserAgent.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x400000000000L) != 0) @@ -1648,6 +1639,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x100000L) != 0) + { + value = _headers._Authority; + return true; + } + return false; + } if (HeaderNames.RequestId.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x2000000000000L) != 0) @@ -2312,18 +2312,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 5: { - if (ReferenceEquals(HeaderNames.Path, key)) - { - _bits |= 0x400000L; - _headers._Path = value; - return; - } if (ReferenceEquals(HeaderNames.Allow, key)) { _bits |= 0x800L; _headers._Allow = value; return; } + if (ReferenceEquals(HeaderNames.Path, key)) + { + _bits |= 0x400000L; + _headers._Path = value; + return; + } if (ReferenceEquals(HeaderNames.Range, key)) { _bits |= 0x80000000000L; @@ -2331,18 +2331,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 0x400000L; - _headers._Path = value; - return; - } if (HeaderNames.Allow.Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 0x800L; _headers._Allow = value; return; } + if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 0x400000L; + _headers._Path = value; + return; + } if (HeaderNames.Range.Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 0x80000000000L; @@ -2418,18 +2418,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 7: { - if (ReferenceEquals(HeaderNames.Method, key)) - { - _bits |= 0x200000L; - _headers._Method = value; - return; - } - if (ReferenceEquals(HeaderNames.Scheme, key)) - { - _bits |= 0x800000L; - _headers._Scheme = value; - return; - } if (ReferenceEquals(HeaderNames.Trailer, key)) { _bits |= 0x40L; @@ -2454,6 +2442,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _headers._Expires = value; return; } + if (ReferenceEquals(HeaderNames.Method, key)) + { + _bits |= 0x200000L; + _headers._Method = value; + return; + } + if (ReferenceEquals(HeaderNames.Scheme, key)) + { + _bits |= 0x800000L; + _headers._Scheme = value; + return; + } if (ReferenceEquals(HeaderNames.Referer, key)) { _bits |= 0x40000000000L; @@ -2461,18 +2461,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return; } - if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 0x200000L; - _headers._Method = value; - return; - } - if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 0x800000L; - _headers._Scheme = value; - return; - } if (HeaderNames.Trailer.Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 0x40L; @@ -2497,6 +2485,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _headers._Expires = value; return; } + if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 0x200000L; + _headers._Method = value; + return; + } + if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 0x800000L; + _headers._Scheme = value; + return; + } if (HeaderNames.Referer.Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 0x40000000000L; @@ -2559,12 +2559,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _headers._Connection = value; return; } - if (ReferenceEquals(HeaderNames.Authority, key)) - { - _bits |= 0x100000L; - _headers._Authority = value; - return; - } if (ReferenceEquals(HeaderNames.UserAgent, key)) { _bits |= 0x400000000000L; @@ -2577,6 +2571,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _headers._KeepAlive = value; return; } + if (ReferenceEquals(HeaderNames.Authority, key)) + { + _bits |= 0x100000L; + _headers._Authority = value; + return; + } if (ReferenceEquals(HeaderNames.RequestId, key)) { _bits |= 0x2000000000000L; @@ -2596,12 +2596,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _headers._Connection = value; return; } - if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 0x100000L; - _headers._Authority = value; - return; - } if (HeaderNames.UserAgent.Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 0x400000000000L; @@ -2614,6 +2608,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http _headers._KeepAlive = value; return; } + if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 0x100000L; + _headers._Authority = value; + return; + } if (HeaderNames.RequestId.Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 0x2000000000000L; @@ -3156,16 +3156,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 5: { - if (ReferenceEquals(HeaderNames.Path, key)) - { - if ((_bits & 0x400000L) == 0) - { - _bits |= 0x400000L; - _headers._Path = value; - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.Allow, key)) { if ((_bits & 0x800L) == 0) @@ -3176,6 +3166,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Path, key)) + { + if ((_bits & 0x400000L) == 0) + { + _bits |= 0x400000L; + _headers._Path = value; + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.Range, key)) { if ((_bits & 0x80000000000L) == 0) @@ -3187,16 +3187,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return false; } - if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x400000L) == 0) - { - _bits |= 0x400000L; - _headers._Path = value; - return true; - } - return false; - } if (HeaderNames.Allow.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x800L) == 0) @@ -3207,6 +3197,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x400000L) == 0) + { + _bits |= 0x400000L; + _headers._Path = value; + return true; + } + return false; + } if (HeaderNames.Range.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x80000000000L) == 0) @@ -3326,26 +3326,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 7: { - if (ReferenceEquals(HeaderNames.Method, key)) - { - if ((_bits & 0x200000L) == 0) - { - _bits |= 0x200000L; - _headers._Method = value; - return true; - } - return false; - } - if (ReferenceEquals(HeaderNames.Scheme, key)) - { - if ((_bits & 0x800000L) == 0) - { - _bits |= 0x800000L; - _headers._Scheme = value; - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.Trailer, key)) { if ((_bits & 0x40L) == 0) @@ -3386,6 +3366,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Method, key)) + { + if ((_bits & 0x200000L) == 0) + { + _bits |= 0x200000L; + _headers._Method = value; + return true; + } + return false; + } + if (ReferenceEquals(HeaderNames.Scheme, key)) + { + if ((_bits & 0x800000L) == 0) + { + _bits |= 0x800000L; + _headers._Scheme = value; + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.Referer, key)) { if ((_bits & 0x40000000000L) == 0) @@ -3397,26 +3397,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return false; } - if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x200000L) == 0) - { - _bits |= 0x200000L; - _headers._Method = value; - return true; - } - return false; - } - if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x800000L) == 0) - { - _bits |= 0x800000L; - _headers._Scheme = value; - return true; - } - return false; - } if (HeaderNames.Trailer.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x40L) == 0) @@ -3457,6 +3437,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x200000L) == 0) + { + _bits |= 0x200000L; + _headers._Method = value; + return true; + } + return false; + } + if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x800000L) == 0) + { + _bits |= 0x800000L; + _headers._Scheme = value; + return true; + } + return false; + } if (HeaderNames.Referer.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x40000000000L) == 0) @@ -3551,16 +3551,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } - if (ReferenceEquals(HeaderNames.Authority, key)) - { - if ((_bits & 0x100000L) == 0) - { - _bits |= 0x100000L; - _headers._Authority = value; - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.UserAgent, key)) { if ((_bits & 0x400000000000L) == 0) @@ -3581,6 +3571,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Authority, key)) + { + if ((_bits & 0x100000L) == 0) + { + _bits |= 0x100000L; + _headers._Authority = value; + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.RequestId, key)) { if ((_bits & 0x2000000000000L) == 0) @@ -3612,16 +3612,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } - if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x100000L) == 0) - { - _bits |= 0x100000L; - _headers._Authority = value; - return true; - } - return false; - } if (HeaderNames.UserAgent.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x400000000000L) == 0) @@ -3642,6 +3632,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x100000L) == 0) + { + _bits |= 0x100000L; + _headers._Authority = value; + return true; + } + return false; + } if (HeaderNames.RequestId.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x2000000000000L) == 0) @@ -4408,16 +4408,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 5: { - if (ReferenceEquals(HeaderNames.Path, key)) - { - if ((_bits & 0x400000L) != 0) - { - _bits &= ~0x400000L; - _headers._Path = default(StringValues); - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.Allow, key)) { if ((_bits & 0x800L) != 0) @@ -4428,6 +4418,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Path, key)) + { + if ((_bits & 0x400000L) != 0) + { + _bits &= ~0x400000L; + _headers._Path = default(StringValues); + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.Range, key)) { if ((_bits & 0x80000000000L) != 0) @@ -4439,16 +4439,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return false; } - if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x400000L) != 0) - { - _bits &= ~0x400000L; - _headers._Path = default(StringValues); - return true; - } - return false; - } if (HeaderNames.Allow.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x800L) != 0) @@ -4459,6 +4449,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Path.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x400000L) != 0) + { + _bits &= ~0x400000L; + _headers._Path = default(StringValues); + return true; + } + return false; + } if (HeaderNames.Range.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x80000000000L) != 0) @@ -4578,26 +4578,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } case 7: { - if (ReferenceEquals(HeaderNames.Method, key)) - { - if ((_bits & 0x200000L) != 0) - { - _bits &= ~0x200000L; - _headers._Method = default(StringValues); - return true; - } - return false; - } - if (ReferenceEquals(HeaderNames.Scheme, key)) - { - if ((_bits & 0x800000L) != 0) - { - _bits &= ~0x800000L; - _headers._Scheme = default(StringValues); - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.Trailer, key)) { if ((_bits & 0x40L) != 0) @@ -4638,6 +4618,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Method, key)) + { + if ((_bits & 0x200000L) != 0) + { + _bits &= ~0x200000L; + _headers._Method = default(StringValues); + return true; + } + return false; + } + if (ReferenceEquals(HeaderNames.Scheme, key)) + { + if ((_bits & 0x800000L) != 0) + { + _bits &= ~0x800000L; + _headers._Scheme = default(StringValues); + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.Referer, key)) { if ((_bits & 0x40000000000L) != 0) @@ -4649,26 +4649,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return false; } - if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x200000L) != 0) - { - _bits &= ~0x200000L; - _headers._Method = default(StringValues); - return true; - } - return false; - } - if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x800000L) != 0) - { - _bits &= ~0x800000L; - _headers._Scheme = default(StringValues); - return true; - } - return false; - } if (HeaderNames.Trailer.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x40L) != 0) @@ -4709,6 +4689,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Method.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x200000L) != 0) + { + _bits &= ~0x200000L; + _headers._Method = default(StringValues); + return true; + } + return false; + } + if (HeaderNames.Scheme.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x800000L) != 0) + { + _bits &= ~0x800000L; + _headers._Scheme = default(StringValues); + return true; + } + return false; + } if (HeaderNames.Referer.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x40000000000L) != 0) @@ -4803,16 +4803,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } - if (ReferenceEquals(HeaderNames.Authority, key)) - { - if ((_bits & 0x100000L) != 0) - { - _bits &= ~0x100000L; - _headers._Authority = default(StringValues); - return true; - } - return false; - } if (ReferenceEquals(HeaderNames.UserAgent, key)) { if ((_bits & 0x400000000000L) != 0) @@ -4833,6 +4823,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (ReferenceEquals(HeaderNames.Authority, key)) + { + if ((_bits & 0x100000L) != 0) + { + _bits &= ~0x100000L; + _headers._Authority = default(StringValues); + return true; + } + return false; + } if (ReferenceEquals(HeaderNames.RequestId, key)) { if ((_bits & 0x2000000000000L) != 0) @@ -4864,16 +4864,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } - if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if ((_bits & 0x100000L) != 0) - { - _bits &= ~0x100000L; - _headers._Authority = default(StringValues); - return true; - } - return false; - } if (HeaderNames.UserAgent.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x400000000000L) != 0) @@ -4894,6 +4884,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } return false; } + if (HeaderNames.Authority.Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 0x100000L) != 0) + { + _bits &= ~0x100000L; + _headers._Authority = default(StringValues); + return true; + } + return false; + } if (HeaderNames.RequestId.Equals(key, StringComparison.OrdinalIgnoreCase)) { if ((_bits & 0x2000000000000L) != 0) @@ -5532,46 +5532,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http tempBits &= ~0x2L; } - if ((tempBits & 0x100000L) != 0) - { - _headers._Authority = default; - if((tempBits & ~0x100000L) == 0) - { - return; - } - tempBits &= ~0x100000L; - } - - if ((tempBits & 0x200000L) != 0) - { - _headers._Method = default; - if((tempBits & ~0x200000L) == 0) - { - return; - } - tempBits &= ~0x200000L; - } - - if ((tempBits & 0x400000L) != 0) - { - _headers._Path = default; - if((tempBits & ~0x400000L) == 0) - { - return; - } - tempBits &= ~0x400000L; - } - - if ((tempBits & 0x800000L) != 0) - { - _headers._Scheme = default; - if((tempBits & ~0x800000L) == 0) - { - return; - } - tempBits &= ~0x800000L; - } - if ((tempBits & 0x1000000L) != 0) { _headers._Accept = default; @@ -5792,6 +5752,46 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http tempBits &= ~0x80000L; } + if ((tempBits & 0x100000L) != 0) + { + _headers._Authority = default; + if((tempBits & ~0x100000L) == 0) + { + return; + } + tempBits &= ~0x100000L; + } + + if ((tempBits & 0x200000L) != 0) + { + _headers._Method = default; + if((tempBits & ~0x200000L) == 0) + { + return; + } + tempBits &= ~0x200000L; + } + + if ((tempBits & 0x400000L) != 0) + { + _headers._Path = default; + if((tempBits & ~0x400000L) == 0) + { + return; + } + tempBits &= ~0x400000L; + } + + if ((tempBits & 0x800000L) != 0) + { + _headers._Scheme = default; + if((tempBits & ~0x800000L) == 0) + { + return; + } + tempBits &= ~0x800000L; + } + if ((tempBits & 0x2000000L) != 0) { _headers._AcceptCharset = default; @@ -6785,13 +6785,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http } break; case 10: - if (((Unsafe.ReadUnaligned(ref nameStart) & 0xdfdfdfdfdfdfdfffuL) == 0x49524f485455413auL) && ((Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref nameStart, (IntPtr)(4 * sizeof(ushort)))) & 0xdfdfu) == 0x5954u)) - { - flag = 0x100000L; - values = ref _headers._Authority; - nameStr = HeaderNames.Authority; - } - else if (((Unsafe.ReadUnaligned(ref nameStart) & 0xdfdfdfdfdfdfdfdfuL) == 0x495443454e4e4f43uL) && ((Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref nameStart, (IntPtr)(4 * sizeof(ushort)))) & 0xdfdfu) == 0x4e4fu)) + if (((Unsafe.ReadUnaligned(ref nameStart) & 0xdfdfdfdfdfdfdfdfuL) == 0x495443454e4e4f43uL) && ((Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref nameStart, (IntPtr)(4 * sizeof(ushort)))) & 0xdfdfu) == 0x4e4fu)) { flag = 0x2L; values = ref _headers._Connection; @@ -6803,6 +6797,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http values = ref _headers._UserAgent; nameStr = HeaderNames.UserAgent; } + else if (((Unsafe.ReadUnaligned(ref nameStart) & 0xdfdfdfdfdfdfdfffuL) == 0x49524f485455413auL) && ((Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref nameStart, (IntPtr)(4 * sizeof(ushort)))) & 0xdfdfu) == 0x5954u)) + { + flag = 0x100000L; + values = ref _headers._Authority; + nameStr = HeaderNames.Authority; + } else if (((Unsafe.ReadUnaligned(ref nameStart) & 0xdfdfdfffdfdfdfdfuL) == 0x494c412d5045454buL) && ((Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref nameStart, (IntPtr)(4 * sizeof(ushort)))) & 0xdfdfu) == 0x4556u)) { flag = 0x10L; diff --git a/src/Servers/Kestrel/Kestrel/test/GeneratedCodeTests.cs b/src/Servers/Kestrel/Kestrel/test/GeneratedCodeTests.cs index 52201ce333..7997e21110 100644 --- a/src/Servers/Kestrel/Kestrel/test/GeneratedCodeTests.cs +++ b/src/Servers/Kestrel/Kestrel/test/GeneratedCodeTests.cs @@ -5,11 +5,19 @@ using System; using System.IO; using Microsoft.AspNetCore.Testing; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public class GeneratedCodeTests { + private readonly ITestOutputHelper _output; + + public GeneratedCodeTests(ITestOutputHelper output) + { + _output = output; + } + [ConditionalFact] public void GeneratedCodeIsUpToDate() { @@ -50,12 +58,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests var testTransportMultiplxedConnectionGenerated = File.ReadAllText(testTransportMultiplexedConnectionGeneratedPath); var testTransportConnectionGenerated = File.ReadAllText(testTransportConnectionGeneratedPath); - AssertFileContentEqual(currentHttpHeadersGenerated, testHttpHeadersGenerated); - AssertFileContentEqual(currentHttpProtocolGenerated, testHttpProtocolGenerated); - AssertFileContentEqual(currentHttpUtilitiesGenerated, testHttpUtilitiesGenerated); - AssertFileContentEqual(currentHttp2ConnectionGenerated, testHttp2ConnectionGenerated); - AssertFileContentEqual(currentTransportConnectionBaseGenerated, testTransportMultiplxedConnectionGenerated); - AssertFileContentEqual(currentTransportConnectionGenerated, testTransportConnectionGenerated); + AssertFileContentEqual(currentHttpHeadersGenerated, testHttpHeadersGenerated, "HTTP headers"); + AssertFileContentEqual(currentHttpProtocolGenerated, testHttpProtocolGenerated, "HTTP protocol"); + AssertFileContentEqual(currentHttpUtilitiesGenerated, testHttpUtilitiesGenerated, "HTTP utilities"); + AssertFileContentEqual(currentHttp2ConnectionGenerated, testHttp2ConnectionGenerated, "HTTP2 connection"); + AssertFileContentEqual(currentTransportConnectionBaseGenerated, testTransportMultiplxedConnectionGenerated, "TransportConnectionBase"); + AssertFileContentEqual(currentTransportConnectionGenerated, testTransportConnectionGenerated, "TransportConnection"); } finally { @@ -68,9 +76,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - private void AssertFileContentEqual(string expected, string actual) + private void AssertFileContentEqual(string expected, string actual, string type) { - Assert.Equal(expected.Trim(), actual.Trim(), ignoreLineEndingDifferences: true); + try + { + Assert.Equal(expected.Trim(), actual.Trim(), ignoreLineEndingDifferences: true); + } + catch (Exception) + { + _output.WriteLine($"Error when comparing {type}."); + _output.WriteLine("Expected:"); + _output.WriteLine(expected); + _output.WriteLine("Actual:"); + _output.WriteLine(actual); + throw; + } } } } diff --git a/src/Servers/Kestrel/shared/KnownHeaders.cs b/src/Servers/Kestrel/shared/KnownHeaders.cs index 9e21aba6a8..bd8ff66702 100644 --- a/src/Servers/Kestrel/shared/KnownHeaders.cs +++ b/src/Servers/Kestrel/shared/KnownHeaders.cs @@ -21,10 +21,6 @@ namespace CodeGenerator { var requestPrimaryHeaders = new[] { - ":authority", - ":method", - ":path", - ":scheme", "Accept", "Connection", "Host", @@ -216,7 +212,7 @@ namespace CodeGenerator static string AppendSwitch(IEnumerable> values) => $@"switch (name.Length) {{{Each(values, byLength => $@" - case {byLength.Key}:{AppendSwitchSection(byLength.Key, byLength.OrderBy(h => (h.PrimaryHeader ? "_" : "") + h.Name))} + case {byLength.Key}:{AppendSwitchSection(byLength.Key, byLength.OrderBy(h => h, KnownHeaderComparer.Instance).ToList())} break;")} }}"; @@ -288,7 +284,7 @@ namespace CodeGenerator } } - static string AppendSwitchSection(int length, IOrderedEnumerable values) + static string AppendSwitchSection(int length, IList values) { var useVarForFirstTerm = values.Count() > 1 && values.Select(h => h.FirstNameIgnoreCaseSegment()).Distinct().Count() == 1; var firstTermVarExpression = values.Select(h => h.FirstNameIgnoreCaseSegment()).FirstOrDefault(); @@ -329,8 +325,13 @@ namespace CodeGenerator } } - var groups = values.GroupBy(header => header.EqualIgnoreCaseBytesFirstTerm()); - return start + $@"{Each(groups, (byFirstTerm, i) => $@"{(byFirstTerm.Count() == 1 ? $@"{Each(byFirstTerm, header => $@" + // Group headers together that have the same ignore equal case equals check for the first term. + // There will probably only be more than one item in a group for Content-Encoding, Content-Language, Content-Location. + var groups = values.GroupBy(header => header.EqualIgnoreCaseBytesFirstTerm()) + .OrderBy(g => g.First(), KnownHeaderComparer.Instance) + .ToList(); + + return start + $@"{Each(groups, (byFirstTerm, i) => $@"{(byFirstTerm.Count() == 1 ? $@"{Each(byFirstTerm, header => $@" {(i > 0 ? "else " : "")}if ({header.EqualIgnoreCaseBytes(firstTermVar)}) {{{GenerateIfBody(header)} }}")}" : $@" @@ -342,6 +343,7 @@ namespace CodeGenerator }}")}")}"; } + [DebuggerDisplay("{Name}")] public class KnownHeader { public string Name { get; set; } @@ -654,7 +656,7 @@ namespace CodeGenerator var responseTrailers = ResponseTrailers; var allHeaderNames = RequestHeaders.Concat(ResponseHeaders).Concat(ResponseTrailers) - .Select(h => h.Identifier).Distinct().OrderBy(n => n).ToArray(); + .Select(h => h.Identifier).Distinct().OrderBy(n => n, StringComparer.InvariantCulture).ToArray(); var loops = new[] { @@ -1174,13 +1176,6 @@ $@" private void Clear(long bitsToClear) ")}}}"; } - private class HPackGroup - { - public int[] HPackStaticTableIndexes { get; set; } - public KnownHeader Header { get; set; } - public string Name { get; set; } - } - private static IEnumerable GroupHPack(KnownHeader[] headers) { var staticHeaders = new (int Index, HeaderField HeaderField)[H2StaticTable.Count]; @@ -1201,5 +1196,33 @@ $@" private void Clear(long bitsToClear) return groupedHeaders; } + + private class HPackGroup + { + public int[] HPackStaticTableIndexes { get; set; } + public KnownHeader Header { get; set; } + public string Name { get; set; } + } + + private class KnownHeaderComparer : IComparer + { + public static readonly KnownHeaderComparer Instance = new KnownHeaderComparer(); + + public int Compare(KnownHeader x, KnownHeader y) + { + // Primary headers appear first + if (x.PrimaryHeader && !y.PrimaryHeader) + { + return -1; + } + if (y.PrimaryHeader && !x.PrimaryHeader) + { + return 1; + } + + // Then alphabetical + return StringComparer.InvariantCulture.Compare(x.Name, y.Name); + } + } } }