diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs index 128040c1d..f7109710c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs @@ -43,6 +43,9 @@ internal static BadHttpRequestException GetException(RequestRejectionReason reas case RequestRejectionReason.MalformedRequestInvalidHeaders: ex = new BadHttpRequestException("Malformed request: invalid headers.", StatusCodes.Status400BadRequest); break; + case RequestRejectionReason.MultipleContentLengths: + ex = new BadHttpRequestException("Multiple Content-Length headers.", StatusCodes.Status400BadRequest); + break; case RequestRejectionReason.UnexpectedEndOfRequestContent: ex = new BadHttpRequestException("Unexpected end of request content.", StatusCodes.Status400BadRequest); break; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 66868595f..e72549c71 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -41,7 +41,6 @@ public abstract partial class Frame : IFrameControl private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive"); private static readonly byte[] _bytesTransferEncodingChunked = Encoding.ASCII.GetBytes("\r\nTransfer-Encoding: chunked"); private static readonly byte[] _bytesHttpVersion11 = Encoding.ASCII.GetBytes("HTTP/1.1 "); - private static readonly byte[] _bytesContentLengthZero = Encoding.ASCII.GetBytes("\r\nContent-Length: 0"); private static readonly byte[] _bytesEndHeaders = Encoding.ASCII.GetBytes("\r\n\r\n"); private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); @@ -657,12 +656,12 @@ private void VerifyAndUpdateWrite(int count) if (responseHeaders != null && !responseHeaders.HasTransferEncoding && - responseHeaders.HasContentLength && - _responseBytesWritten + count > responseHeaders.HeaderContentLengthValue.Value) + responseHeaders.ContentLength.HasValue && + _responseBytesWritten + count > responseHeaders.ContentLength.Value) { _keepAlive = false; throw new InvalidOperationException( - $"Response Content-Length mismatch: too many bytes written ({_responseBytesWritten + count} of {responseHeaders.HeaderContentLengthValue.Value})."); + $"Response Content-Length mismatch: too many bytes written ({_responseBytesWritten + count} of {responseHeaders.ContentLength.Value})."); } _responseBytesWritten += count; @@ -679,8 +678,8 @@ private void CheckLastWrite() // Called after VerifyAndUpdateWrite(), so _responseBytesWritten has already been updated. if (responseHeaders != null && !responseHeaders.HasTransferEncoding && - responseHeaders.HasContentLength && - _responseBytesWritten == responseHeaders.HeaderContentLengthValue.Value) + responseHeaders.ContentLength.HasValue && + _responseBytesWritten == responseHeaders.ContentLength.Value) { _abortedCts = null; } @@ -692,8 +691,8 @@ protected void VerifyResponseContentLength() if (!HttpMethods.IsHead(Method) && !responseHeaders.HasTransferEncoding && - responseHeaders.HeaderContentLengthValue.HasValue && - _responseBytesWritten < responseHeaders.HeaderContentLengthValue.Value) + responseHeaders.ContentLength.HasValue && + _responseBytesWritten < responseHeaders.ContentLength.Value) { // We need to close the connection if any bytes were written since the client // cannot be certain of how many bytes it will receive. @@ -703,7 +702,7 @@ protected void VerifyResponseContentLength() } ReportApplicationError(new InvalidOperationException( - $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.HeaderContentLengthValue.Value}).")); + $"Response Content-Length mismatch: too few bytes written ({_responseBytesWritten} of {responseHeaders.ContentLength.Value}).")); } } @@ -920,13 +919,13 @@ private void CreateResponseHeader( // automatically for HEAD requests or 204, 205, 304 responses. if (_canHaveBody) { - if (!hasTransferEncoding && !responseHeaders.HasContentLength) + if (!hasTransferEncoding && !responseHeaders.ContentLength.HasValue) { if (appCompleted && StatusCode != StatusCodes.Status101SwitchingProtocols) { // Since the app has completed and we are only now generating // the headers we can safely set the Content-Length to 0. - responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + responseHeaders.ContentLength = 0; } else { @@ -1468,7 +1467,7 @@ private void SetErrorResponseHeaders(int statusCode) var dateHeaderValues = DateHeaderValueManager.GetDateHeaderValues(); responseHeaders.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); - responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); + responseHeaders.ContentLength = 0; if (ServerOptions.AddServerHeader) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs index eaa963843..7cfb64ff3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -19,11 +20,12 @@ public StringValues HeaderCacheControl { get { - if (((_bits & 1L) != 0)) + StringValues value; + if ((_bits & 1L) != 0) { - return _headers._CacheControl; + value = _headers._CacheControl; } - return StringValues.Empty; + return value; } set { @@ -35,11 +37,12 @@ public StringValues HeaderConnection { get { - if (((_bits & 2L) != 0)) + StringValues value; + if ((_bits & 2L) != 0) { - return _headers._Connection; + value = _headers._Connection; } - return StringValues.Empty; + return value; } set { @@ -51,11 +54,12 @@ public StringValues HeaderDate { get { - if (((_bits & 4L) != 0)) + StringValues value; + if ((_bits & 4L) != 0) { - return _headers._Date; + value = _headers._Date; } - return StringValues.Empty; + return value; } set { @@ -67,11 +71,12 @@ public StringValues HeaderKeepAlive { get { - if (((_bits & 8L) != 0)) + StringValues value; + if ((_bits & 8L) != 0) { - return _headers._KeepAlive; + value = _headers._KeepAlive; } - return StringValues.Empty; + return value; } set { @@ -83,11 +88,12 @@ public StringValues HeaderPragma { get { - if (((_bits & 16L) != 0)) + StringValues value; + if ((_bits & 16L) != 0) { - return _headers._Pragma; + value = _headers._Pragma; } - return StringValues.Empty; + return value; } set { @@ -99,11 +105,12 @@ public StringValues HeaderTrailer { get { - if (((_bits & 32L) != 0)) + StringValues value; + if ((_bits & 32L) != 0) { - return _headers._Trailer; + value = _headers._Trailer; } - return StringValues.Empty; + return value; } set { @@ -115,11 +122,12 @@ public StringValues HeaderTransferEncoding { get { - if (((_bits & 64L) != 0)) + StringValues value; + if ((_bits & 64L) != 0) { - return _headers._TransferEncoding; + value = _headers._TransferEncoding; } - return StringValues.Empty; + return value; } set { @@ -131,11 +139,12 @@ public StringValues HeaderUpgrade { get { - if (((_bits & 128L) != 0)) + StringValues value; + if ((_bits & 128L) != 0) { - return _headers._Upgrade; + value = _headers._Upgrade; } - return StringValues.Empty; + return value; } set { @@ -147,11 +156,12 @@ public StringValues HeaderVia { get { - if (((_bits & 256L) != 0)) + StringValues value; + if ((_bits & 256L) != 0) { - return _headers._Via; + value = _headers._Via; } - return StringValues.Empty; + return value; } set { @@ -163,11 +173,12 @@ public StringValues HeaderWarning { get { - if (((_bits & 512L) != 0)) + StringValues value; + if ((_bits & 512L) != 0) { - return _headers._Warning; + value = _headers._Warning; } - return StringValues.Empty; + return value; } set { @@ -179,11 +190,12 @@ public StringValues HeaderAllow { get { - if (((_bits & 1024L) != 0)) + StringValues value; + if ((_bits & 1024L) != 0) { - return _headers._Allow; + value = _headers._Allow; } - return StringValues.Empty; + return value; } set { @@ -191,35 +203,20 @@ public StringValues HeaderAllow _headers._Allow = value; } } - public StringValues HeaderContentLength - { - get - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - return StringValues.Empty; - } - set - { - _bits |= 2048L; - _headers._ContentLength = value; - } - } public StringValues HeaderContentType { get { - if (((_bits & 4096L) != 0)) + StringValues value; + if ((_bits & 2048L) != 0) { - return _headers._ContentType; + value = _headers._ContentType; } - return StringValues.Empty; + return value; } set { - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; } } @@ -227,15 +224,16 @@ public StringValues HeaderContentEncoding { get { - if (((_bits & 8192L) != 0)) + StringValues value; + if ((_bits & 4096L) != 0) { - return _headers._ContentEncoding; + value = _headers._ContentEncoding; } - return StringValues.Empty; + return value; } set { - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; } } @@ -243,15 +241,16 @@ public StringValues HeaderContentLanguage { get { - if (((_bits & 16384L) != 0)) + StringValues value; + if ((_bits & 8192L) != 0) { - return _headers._ContentLanguage; + value = _headers._ContentLanguage; } - return StringValues.Empty; + return value; } set { - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; } } @@ -259,15 +258,16 @@ public StringValues HeaderContentLocation { get { - if (((_bits & 32768L) != 0)) + StringValues value; + if ((_bits & 16384L) != 0) { - return _headers._ContentLocation; + value = _headers._ContentLocation; } - return StringValues.Empty; + return value; } set { - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; } } @@ -275,15 +275,16 @@ public StringValues HeaderContentMD5 { get { - if (((_bits & 65536L) != 0)) + StringValues value; + if ((_bits & 32768L) != 0) { - return _headers._ContentMD5; + value = _headers._ContentMD5; } - return StringValues.Empty; + return value; } set { - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; } } @@ -291,15 +292,16 @@ public StringValues HeaderContentRange { get { - if (((_bits & 131072L) != 0)) + StringValues value; + if ((_bits & 65536L) != 0) { - return _headers._ContentRange; + value = _headers._ContentRange; } - return StringValues.Empty; + return value; } set { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; } } @@ -307,15 +309,16 @@ public StringValues HeaderExpires { get { - if (((_bits & 262144L) != 0)) + StringValues value; + if ((_bits & 131072L) != 0) { - return _headers._Expires; + value = _headers._Expires; } - return StringValues.Empty; + return value; } set { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; } } @@ -323,15 +326,16 @@ public StringValues HeaderLastModified { get { - if (((_bits & 524288L) != 0)) + StringValues value; + if ((_bits & 262144L) != 0) { - return _headers._LastModified; + value = _headers._LastModified; } - return StringValues.Empty; + return value; } set { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; } } @@ -339,15 +343,16 @@ public StringValues HeaderAccept { get { - if (((_bits & 1048576L) != 0)) + StringValues value; + if ((_bits & 524288L) != 0) { - return _headers._Accept; + value = _headers._Accept; } - return StringValues.Empty; + return value; } set { - _bits |= 1048576L; + _bits |= 524288L; _headers._Accept = value; } } @@ -355,15 +360,16 @@ public StringValues HeaderAcceptCharset { get { - if (((_bits & 2097152L) != 0)) + StringValues value; + if ((_bits & 1048576L) != 0) { - return _headers._AcceptCharset; + value = _headers._AcceptCharset; } - return StringValues.Empty; + return value; } set { - _bits |= 2097152L; + _bits |= 1048576L; _headers._AcceptCharset = value; } } @@ -371,15 +377,16 @@ public StringValues HeaderAcceptEncoding { get { - if (((_bits & 4194304L) != 0)) + StringValues value; + if ((_bits & 2097152L) != 0) { - return _headers._AcceptEncoding; + value = _headers._AcceptEncoding; } - return StringValues.Empty; + return value; } set { - _bits |= 4194304L; + _bits |= 2097152L; _headers._AcceptEncoding = value; } } @@ -387,15 +394,16 @@ public StringValues HeaderAcceptLanguage { get { - if (((_bits & 8388608L) != 0)) + StringValues value; + if ((_bits & 4194304L) != 0) { - return _headers._AcceptLanguage; + value = _headers._AcceptLanguage; } - return StringValues.Empty; + return value; } set { - _bits |= 8388608L; + _bits |= 4194304L; _headers._AcceptLanguage = value; } } @@ -403,15 +411,16 @@ public StringValues HeaderAuthorization { get { - if (((_bits & 16777216L) != 0)) + StringValues value; + if ((_bits & 8388608L) != 0) { - return _headers._Authorization; + value = _headers._Authorization; } - return StringValues.Empty; + return value; } set { - _bits |= 16777216L; + _bits |= 8388608L; _headers._Authorization = value; } } @@ -419,15 +428,16 @@ public StringValues HeaderCookie { get { - if (((_bits & 33554432L) != 0)) + StringValues value; + if ((_bits & 16777216L) != 0) { - return _headers._Cookie; + value = _headers._Cookie; } - return StringValues.Empty; + return value; } set { - _bits |= 33554432L; + _bits |= 16777216L; _headers._Cookie = value; } } @@ -435,15 +445,16 @@ public StringValues HeaderExpect { get { - if (((_bits & 67108864L) != 0)) + StringValues value; + if ((_bits & 33554432L) != 0) { - return _headers._Expect; + value = _headers._Expect; } - return StringValues.Empty; + return value; } set { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Expect = value; } } @@ -451,15 +462,16 @@ public StringValues HeaderFrom { get { - if (((_bits & 134217728L) != 0)) + StringValues value; + if ((_bits & 67108864L) != 0) { - return _headers._From; + value = _headers._From; } - return StringValues.Empty; + return value; } set { - _bits |= 134217728L; + _bits |= 67108864L; _headers._From = value; } } @@ -467,15 +479,16 @@ public StringValues HeaderHost { get { - if (((_bits & 268435456L) != 0)) + StringValues value; + if ((_bits & 134217728L) != 0) { - return _headers._Host; + value = _headers._Host; } - return StringValues.Empty; + return value; } set { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Host = value; } } @@ -483,15 +496,16 @@ public StringValues HeaderIfMatch { get { - if (((_bits & 536870912L) != 0)) + StringValues value; + if ((_bits & 268435456L) != 0) { - return _headers._IfMatch; + value = _headers._IfMatch; } - return StringValues.Empty; + return value; } set { - _bits |= 536870912L; + _bits |= 268435456L; _headers._IfMatch = value; } } @@ -499,15 +513,16 @@ public StringValues HeaderIfModifiedSince { get { - if (((_bits & 1073741824L) != 0)) + StringValues value; + if ((_bits & 536870912L) != 0) { - return _headers._IfModifiedSince; + value = _headers._IfModifiedSince; } - return StringValues.Empty; + return value; } set { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._IfModifiedSince = value; } } @@ -515,15 +530,16 @@ public StringValues HeaderIfNoneMatch { get { - if (((_bits & 2147483648L) != 0)) + StringValues value; + if ((_bits & 1073741824L) != 0) { - return _headers._IfNoneMatch; + value = _headers._IfNoneMatch; } - return StringValues.Empty; + return value; } set { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._IfNoneMatch = value; } } @@ -531,15 +547,16 @@ public StringValues HeaderIfRange { get { - if (((_bits & 4294967296L) != 0)) + StringValues value; + if ((_bits & 2147483648L) != 0) { - return _headers._IfRange; + value = _headers._IfRange; } - return StringValues.Empty; + return value; } set { - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._IfRange = value; } } @@ -547,15 +564,16 @@ public StringValues HeaderIfUnmodifiedSince { get { - if (((_bits & 8589934592L) != 0)) + StringValues value; + if ((_bits & 4294967296L) != 0) { - return _headers._IfUnmodifiedSince; + value = _headers._IfUnmodifiedSince; } - return StringValues.Empty; + return value; } set { - _bits |= 8589934592L; + _bits |= 4294967296L; _headers._IfUnmodifiedSince = value; } } @@ -563,15 +581,16 @@ public StringValues HeaderMaxForwards { get { - if (((_bits & 17179869184L) != 0)) + StringValues value; + if ((_bits & 8589934592L) != 0) { - return _headers._MaxForwards; + value = _headers._MaxForwards; } - return StringValues.Empty; + return value; } set { - _bits |= 17179869184L; + _bits |= 8589934592L; _headers._MaxForwards = value; } } @@ -579,15 +598,16 @@ public StringValues HeaderProxyAuthorization { get { - if (((_bits & 34359738368L) != 0)) + StringValues value; + if ((_bits & 17179869184L) != 0) { - return _headers._ProxyAuthorization; + value = _headers._ProxyAuthorization; } - return StringValues.Empty; + return value; } set { - _bits |= 34359738368L; + _bits |= 17179869184L; _headers._ProxyAuthorization = value; } } @@ -595,15 +615,16 @@ public StringValues HeaderReferer { get { - if (((_bits & 68719476736L) != 0)) + StringValues value; + if ((_bits & 34359738368L) != 0) { - return _headers._Referer; + value = _headers._Referer; } - return StringValues.Empty; + return value; } set { - _bits |= 68719476736L; + _bits |= 34359738368L; _headers._Referer = value; } } @@ -611,15 +632,16 @@ public StringValues HeaderRange { get { - if (((_bits & 137438953472L) != 0)) + StringValues value; + if ((_bits & 68719476736L) != 0) { - return _headers._Range; + value = _headers._Range; } - return StringValues.Empty; + return value; } set { - _bits |= 137438953472L; + _bits |= 68719476736L; _headers._Range = value; } } @@ -627,15 +649,16 @@ public StringValues HeaderTE { get { - if (((_bits & 274877906944L) != 0)) + StringValues value; + if ((_bits & 137438953472L) != 0) { - return _headers._TE; + value = _headers._TE; } - return StringValues.Empty; + return value; } set { - _bits |= 274877906944L; + _bits |= 137438953472L; _headers._TE = value; } } @@ -643,15 +666,16 @@ public StringValues HeaderTranslate { get { - if (((_bits & 549755813888L) != 0)) + StringValues value; + if ((_bits & 274877906944L) != 0) { - return _headers._Translate; + value = _headers._Translate; } - return StringValues.Empty; + return value; } set { - _bits |= 549755813888L; + _bits |= 274877906944L; _headers._Translate = value; } } @@ -659,15 +683,16 @@ public StringValues HeaderUserAgent { get { - if (((_bits & 1099511627776L) != 0)) + StringValues value; + if ((_bits & 549755813888L) != 0) { - return _headers._UserAgent; + value = _headers._UserAgent; } - return StringValues.Empty; + return value; } set { - _bits |= 1099511627776L; + _bits |= 549755813888L; _headers._UserAgent = value; } } @@ -675,15 +700,16 @@ public StringValues HeaderOrigin { get { - if (((_bits & 2199023255552L) != 0)) + StringValues value; + if ((_bits & 1099511627776L) != 0) { - return _headers._Origin; + value = _headers._Origin; } - return StringValues.Empty; + return value; } set { - _bits |= 2199023255552L; + _bits |= 1099511627776L; _headers._Origin = value; } } @@ -691,15 +717,16 @@ public StringValues HeaderAccessControlRequestMethod { get { - if (((_bits & 4398046511104L) != 0)) + StringValues value; + if ((_bits & 2199023255552L) != 0) { - return _headers._AccessControlRequestMethod; + value = _headers._AccessControlRequestMethod; } - return StringValues.Empty; + return value; } set { - _bits |= 4398046511104L; + _bits |= 2199023255552L; _headers._AccessControlRequestMethod = value; } } @@ -707,24 +734,42 @@ public StringValues HeaderAccessControlRequestHeaders { get { - if (((_bits & 8796093022208L) != 0)) + StringValues value; + if ((_bits & 4398046511104L) != 0) { - return _headers._AccessControlRequestHeaders; + value = _headers._AccessControlRequestHeaders; } - return StringValues.Empty; + return value; } set { - _bits |= 8796093022208L; + _bits |= 4398046511104L; _headers._AccessControlRequestHeaders = value; } } - + public StringValues HeaderContentLength + { + get + { + StringValues value; + if (_contentLength.HasValue) + { + value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + } + return value; + } + set + { + _contentLength = ParseContentLength(value); + } + } + protected override int GetCountFast() { - return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); + return (_contentLength.HasValue ? 1 : 0 ) + BitCount(_bits) + (MaybeUnknown?.Count ?? 0); } - protected override StringValues GetValueFast(string key) + + protected override bool TryGetValueFast(string key, out StringValues value) { switch (key.Length) { @@ -732,613 +777,480 @@ protected override StringValues GetValueFast(string key) { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) - { - return _headers._CacheControl; - } - else + if ((_bits & 1L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._CacheControl; + return true; } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { - return _headers._ContentRange; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._ContentRange; + return true; } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) - { - return _headers._LastModified; - } - else + if ((_bits & 262144L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._LastModified; + return true; } + return false; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) - { - return _headers._Authorization; - } - else + if ((_bits & 8388608L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Authorization; + return true; } + return false; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) - { - return _headers._IfNoneMatch; - } - else + if ((_bits & 1073741824L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._IfNoneMatch; + return true; } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { - return _headers._Connection; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._Connection; + return true; } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) - { - return _headers._KeepAlive; - } - else + if ((_bits & 8L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._KeepAlive; + return true; } + return false; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1099511627776L) != 0)) - { - return _headers._UserAgent; - } - else + if ((_bits & 549755813888L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._UserAgent; + return true; } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) - { - return _headers._Date; - } - else + if ((_bits & 4L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Date; + return true; } + return false; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { - return _headers._From; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._From; + return true; } + return false; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) - { - return _headers._Host; - } - else + if ((_bits & 134217728L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Host; + return true; } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) - { - return _headers._Pragma; - } - else + if ((_bits & 16L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Pragma; + return true; } + return false; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) - { - return _headers._Accept; - } - else + if ((_bits & 524288L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Accept; + return true; } + return false; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { - return _headers._Cookie; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._Cookie; + return true; } + return false; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) - { - return _headers._Expect; - } - else + if ((_bits & 33554432L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Expect; + return true; } + return false; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2199023255552L) != 0)) - { - return _headers._Origin; - } - else + if ((_bits & 1099511627776L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Origin; + return true; } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) - { - return _headers._Trailer; - } - else + if ((_bits & 32L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Trailer; + return true; } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { - return _headers._Upgrade; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._Upgrade; + return true; } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) - { - return _headers._Warning; - } - else + if ((_bits & 512L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Warning; + return true; } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) - { - return _headers._Expires; - } - else + if ((_bits & 131072L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Expires; + return true; } + return false; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 68719476736L) != 0)) - { - return _headers._Referer; - } - else + if ((_bits & 34359738368L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Referer; + return true; } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { - return _headers._TransferEncoding; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._TransferEncoding; + return true; } + return false; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) - { - return _headers._IfModifiedSince; - } - else + if ((_bits & 536870912L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._IfModifiedSince; + return true; } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) - { - return _headers._Via; - } - else + if ((_bits & 256L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Via; + return true; } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) - { - return _headers._Allow; - } - else + if ((_bits & 1024L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Allow; + return true; } + return false; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 137438953472L) != 0)) - { - return _headers._Range; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) + if ((_bits & 68719476736L) != 0) { - return _headers._AcceptCharset; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._Range; + return true; } + return false; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) - { - return _headers._ContentType; - } - else + if ((_bits & 2048L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._ContentType; + return true; } + return false; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) - { - return _headers._MaxForwards; - } - else + if ((_bits & 8589934592L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._MaxForwards; + return true; } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) - { - return _headers._ContentEncoding; - } - else + if ((_bits & 4096L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._ContentEncoding; + return true; } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { - return _headers._ContentLanguage; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._ContentLanguage; + return true; } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) - { - return _headers._ContentLocation; - } - else + if ((_bits & 16384L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._ContentLocation; + return true; } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) + { + value = _headers._ContentMD5; + return true; + } + return false; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1048576L) != 0) { - return _headers._ContentMD5; + value = _headers._AcceptCharset; + return true; } - else + return false; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) { - ThrowKeyNotFoundException(); + value = HeaderUtilities.FormatInt64(_contentLength.Value); + return true; } + return false; } } break; - case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { - return _headers._AcceptEncoding; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._AcceptEncoding; + return true; } + return false; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) - { - return _headers._AcceptLanguage; - } - else + if ((_bits & 4194304L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._AcceptLanguage; + return true; } + return false; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) - { - return _headers._IfMatch; - } - else + if ((_bits & 268435456L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._IfMatch; + return true; } + return false; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) - { - return _headers._IfRange; - } - else + if ((_bits & 2147483648L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._IfRange; + return true; } + return false; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { - return _headers._IfUnmodifiedSince; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._IfUnmodifiedSince; + return true; } + return false; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) - { - return _headers._ProxyAuthorization; - } - else + if ((_bits & 17179869184L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._ProxyAuthorization; + return true; } + return false; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 274877906944L) != 0)) - { - return _headers._TE; - } - else + if ((_bits & 137438953472L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._TE; + return true; } + return false; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 549755813888L) != 0)) - { - return _headers._Translate; - } - else + if ((_bits & 274877906944L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._Translate; + return true; } + return false; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { - return _headers._AccessControlRequestMethod; - } - else - { - ThrowKeyNotFoundException(); + value = _headers._AccessControlRequestMethod; + return true; } + return false; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8796093022208L) != 0)) - { - return _headers._AccessControlRequestHeaders; - } - else + if ((_bits & 4398046511104L) != 0) { - ThrowKeyNotFoundException(); + value = _headers._AccessControlRequestHeaders; + return true; } + return false; } } break; -} - if (MaybeUnknown == null) - { - ThrowKeyNotFoundException(); } - return MaybeUnknown[key]; + + return MaybeUnknown?.TryGetValue(key, out value) ?? false; } - protected override bool TryGetValueFast(string key, out StringValues value) + + protected override void SetValueFast(string key, StringValues value) { switch (key.Length) { @@ -1346,3300 +1258,2246 @@ protected override bool TryGetValueFast(string key, out StringValues value) { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) - { - value = _headers._CacheControl; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 1L; + _headers._CacheControl = value; + return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) - { - value = _headers._ContentRange; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 65536L; + _headers._ContentRange = value; + return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) - { - value = _headers._LastModified; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 262144L; + _headers._LastModified = value; + return; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) - { - value = _headers._Authorization; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 8388608L; + _headers._Authorization = value; + return; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) - { - value = _headers._IfNoneMatch; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 1073741824L; + _headers._IfNoneMatch = value; + return; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) - { - value = _headers._Connection; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 2L; + _headers._Connection = value; + return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) - { - value = _headers._KeepAlive; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 8L; + _headers._KeepAlive = value; + return; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1099511627776L) != 0)) - { - value = _headers._UserAgent; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 549755813888L; + _headers._UserAgent = value; + return; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) - { - value = _headers._Date; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 4L; + _headers._Date = value; + return; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) - { - value = _headers._From; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 67108864L; + _headers._From = value; + return; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) - { - value = _headers._Host; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 134217728L; + _headers._Host = value; + return; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) - { - value = _headers._Pragma; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 16L; + _headers._Pragma = value; + return; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) - { - value = _headers._Accept; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 524288L; + _headers._Accept = value; + return; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) - { - value = _headers._Cookie; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 16777216L; + _headers._Cookie = value; + return; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) - { - value = _headers._Expect; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 33554432L; + _headers._Expect = value; + return; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2199023255552L) != 0)) - { - value = _headers._Origin; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 1099511627776L; + _headers._Origin = value; + return; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) - { - value = _headers._Trailer; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 32L; + _headers._Trailer = value; + return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) - { - value = _headers._Upgrade; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 128L; + _headers._Upgrade = value; + return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) - { - value = _headers._Warning; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 512L; + _headers._Warning = value; + return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) - { - value = _headers._Expires; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 131072L; + _headers._Expires = value; + return; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 68719476736L) != 0)) - { - value = _headers._Referer; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 34359738368L; + _headers._Referer = value; + return; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) - { - value = _headers._TransferEncoding; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 64L; + _headers._TransferEncoding = value; + return; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) - { - value = _headers._IfModifiedSince; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 536870912L; + _headers._IfModifiedSince = value; + return; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) - { - value = _headers._Via; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 256L; + _headers._Via = value; + return; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) - { - value = _headers._Allow; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 1024L; + _headers._Allow = value; + return; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 137438953472L) != 0)) - { - value = _headers._Range; - return true; - } - else - { - value = StringValues.Empty; - return false; - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - value = _headers._ContentLength; - return true; - } - else - { - value = StringValues.Empty; - return false; - } - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - value = _headers._AcceptCharset; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 68719476736L; + _headers._Range = value; + return; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) - { - value = _headers._ContentType; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 2048L; + _headers._ContentType = value; + return; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) - { - value = _headers._MaxForwards; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 8589934592L; + _headers._MaxForwards = value; + return; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) - { - value = _headers._ContentEncoding; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 4096L; + _headers._ContentEncoding = value; + return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) - { - value = _headers._ContentLanguage; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 8192L; + _headers._ContentLanguage = value; + return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) - { - value = _headers._ContentLocation; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 16384L; + _headers._ContentLocation = value; + return; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) - { - value = _headers._ContentMD5; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 32768L; + _headers._ContentMD5 = value; + return; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _bits |= 1048576L; + _headers._AcceptCharset = value; + return; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _contentLength = ParseContentLength(value.ToString()); + return; } } break; - case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) - { - value = _headers._AcceptEncoding; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 2097152L; + _headers._AcceptEncoding = value; + return; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) - { - value = _headers._AcceptLanguage; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 4194304L; + _headers._AcceptLanguage = value; + return; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) - { - value = _headers._IfMatch; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 268435456L; + _headers._IfMatch = value; + return; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) - { - value = _headers._IfRange; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 2147483648L; + _headers._IfRange = value; + return; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) - { - value = _headers._IfUnmodifiedSince; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 4294967296L; + _headers._IfUnmodifiedSince = value; + return; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) - { - value = _headers._ProxyAuthorization; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 17179869184L; + _headers._ProxyAuthorization = value; + return; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 274877906944L) != 0)) - { - value = _headers._TE; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 137438953472L; + _headers._TE = value; + return; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 549755813888L) != 0)) - { - value = _headers._Translate; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 274877906944L; + _headers._Translate = value; + return; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4398046511104L) != 0)) - { - value = _headers._AccessControlRequestMethod; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 2199023255552L; + _headers._AccessControlRequestMethod = value; + return; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8796093022208L) != 0)) - { - value = _headers._AccessControlRequestHeaders; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + _bits |= 4398046511104L; + _headers._AccessControlRequestHeaders = value; + return; } } break; -} - value = StringValues.Empty; - return MaybeUnknown?.TryGetValue(key, out value) ?? false; + } + + SetValueUnknown(key, value); } - protected override void SetValueFast(string key, StringValues value) + + protected override bool AddValueFast(string key, StringValues value) { - switch (key.Length) { case 13: { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1L; - _headers._CacheControl = value; - return; + if ((_bits & 1L) == 0) + { + _bits |= 1L; + _headers._CacheControl = value; + return true; + } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 131072L; - _headers._ContentRange = value; - return; + if ((_bits & 65536L) == 0) + { + _bits |= 65536L; + _headers._ContentRange = value; + return true; + } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 524288L; - _headers._LastModified = value; - return; + if ((_bits & 262144L) == 0) + { + _bits |= 262144L; + _headers._LastModified = value; + return true; + } + return false; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16777216L; - _headers._Authorization = value; - return; + if ((_bits & 8388608L) == 0) + { + _bits |= 8388608L; + _headers._Authorization = value; + return true; + } + return false; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2147483648L; - _headers._IfNoneMatch = value; - return; + if ((_bits & 1073741824L) == 0) + { + _bits |= 1073741824L; + _headers._IfNoneMatch = value; + return true; + } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2L; - _headers._Connection = value; - return; + if ((_bits & 2L) == 0) + { + _bits |= 2L; + _headers._Connection = value; + return true; + } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8L; - _headers._KeepAlive = value; - return; + if ((_bits & 8L) == 0) + { + _bits |= 8L; + _headers._KeepAlive = value; + return true; + } + return false; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1099511627776L; - _headers._UserAgent = value; - return; + if ((_bits & 549755813888L) == 0) + { + _bits |= 549755813888L; + _headers._UserAgent = value; + return true; + } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4L; - _headers._Date = value; - return; + if ((_bits & 4L) == 0) + { + _bits |= 4L; + _headers._Date = value; + return true; + } + return false; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 134217728L; - _headers._From = value; - return; + if ((_bits & 67108864L) == 0) + { + _bits |= 67108864L; + _headers._From = value; + return true; + } + return false; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 268435456L; - _headers._Host = value; - return; + if ((_bits & 134217728L) == 0) + { + _bits |= 134217728L; + _headers._Host = value; + return true; + } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16L; - _headers._Pragma = value; - return; + if ((_bits & 16L) == 0) + { + _bits |= 16L; + _headers._Pragma = value; + return true; + } + return false; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1048576L; - _headers._Accept = value; - return; + if ((_bits & 524288L) == 0) + { + _bits |= 524288L; + _headers._Accept = value; + return true; + } + return false; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 33554432L; - _headers._Cookie = value; - return; + if ((_bits & 16777216L) == 0) + { + _bits |= 16777216L; + _headers._Cookie = value; + return true; + } + return false; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 67108864L; - _headers._Expect = value; - return; + if ((_bits & 33554432L) == 0) + { + _bits |= 33554432L; + _headers._Expect = value; + return true; + } + return false; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2199023255552L; - _headers._Origin = value; - return; + if ((_bits & 1099511627776L) == 0) + { + _bits |= 1099511627776L; + _headers._Origin = value; + return true; + } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 32L; - _headers._Trailer = value; - return; + if ((_bits & 32L) == 0) + { + _bits |= 32L; + _headers._Trailer = value; + return true; + } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 128L; - _headers._Upgrade = value; - return; + if ((_bits & 128L) == 0) + { + _bits |= 128L; + _headers._Upgrade = value; + return true; + } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 512L; - _headers._Warning = value; - return; + if ((_bits & 512L) == 0) + { + _bits |= 512L; + _headers._Warning = value; + return true; + } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 262144L; - _headers._Expires = value; - return; + if ((_bits & 131072L) == 0) + { + _bits |= 131072L; + _headers._Expires = value; + return true; + } + return false; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 68719476736L; - _headers._Referer = value; - return; + if ((_bits & 34359738368L) == 0) + { + _bits |= 34359738368L; + _headers._Referer = value; + return true; + } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 64L; - _headers._TransferEncoding = value; - return; + if ((_bits & 64L) == 0) + { + _bits |= 64L; + _headers._TransferEncoding = value; + return true; + } + return false; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1073741824L; - _headers._IfModifiedSince = value; - return; + if ((_bits & 536870912L) == 0) + { + _bits |= 536870912L; + _headers._IfModifiedSince = value; + return true; + } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 256L; - _headers._Via = value; - return; + if ((_bits & 256L) == 0) + { + _bits |= 256L; + _headers._Via = value; + return true; + } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1024L; - _headers._Allow = value; - return; + if ((_bits & 1024L) == 0) + { + _bits |= 1024L; + _headers._Allow = value; + return true; + } + return false; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 137438953472L; - _headers._Range = value; - return; - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 2048L; - _headers._ContentLength = value; - return; - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _bits |= 2097152L; - _headers._AcceptCharset = value; - return; + if ((_bits & 68719476736L) == 0) + { + _bits |= 68719476736L; + _headers._Range = value; + return true; + } + return false; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4096L; - _headers._ContentType = value; - return; + if ((_bits & 2048L) == 0) + { + _bits |= 2048L; + _headers._ContentType = value; + return true; + } + return false; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 17179869184L; - _headers._MaxForwards = value; - return; + if ((_bits & 8589934592L) == 0) + { + _bits |= 8589934592L; + _headers._MaxForwards = value; + return true; + } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8192L; - _headers._ContentEncoding = value; - return; + if ((_bits & 4096L) == 0) + { + _bits |= 4096L; + _headers._ContentEncoding = value; + return true; + } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16384L; - _headers._ContentLanguage = value; - return; + if ((_bits & 8192L) == 0) + { + _bits |= 8192L; + _headers._ContentLanguage = value; + return true; + } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 32768L; - _headers._ContentLocation = value; - return; + if ((_bits & 16384L) == 0) + { + _bits |= 16384L; + _headers._ContentLocation = value; + return true; + } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 65536L; - _headers._ContentMD5 = value; - return; + if ((_bits & 32768L) == 0) + { + _bits |= 32768L; + _headers._ContentMD5 = value; + return true; + } + return false; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1048576L) == 0) + { + _bits |= 1048576L; + _headers._AcceptCharset = value; + return true; + } + return false; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (!_contentLength.HasValue) + { + _contentLength = ParseContentLength(value); + return true; + } + return false; } } break; - case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4194304L; - _headers._AcceptEncoding = value; - return; + if ((_bits & 2097152L) == 0) + { + _bits |= 2097152L; + _headers._AcceptEncoding = value; + return true; + } + return false; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8388608L; - _headers._AcceptLanguage = value; - return; + if ((_bits & 4194304L) == 0) + { + _bits |= 4194304L; + _headers._AcceptLanguage = value; + return true; + } + return false; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 536870912L; - _headers._IfMatch = value; - return; + if ((_bits & 268435456L) == 0) + { + _bits |= 268435456L; + _headers._IfMatch = value; + return true; + } + return false; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4294967296L; - _headers._IfRange = value; - return; + if ((_bits & 2147483648L) == 0) + { + _bits |= 2147483648L; + _headers._IfRange = value; + return true; + } + return false; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8589934592L; - _headers._IfUnmodifiedSince = value; - return; + if ((_bits & 4294967296L) == 0) + { + _bits |= 4294967296L; + _headers._IfUnmodifiedSince = value; + return true; + } + return false; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 34359738368L; - _headers._ProxyAuthorization = value; - return; + if ((_bits & 17179869184L) == 0) + { + _bits |= 17179869184L; + _headers._ProxyAuthorization = value; + return true; + } + return false; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 274877906944L; - _headers._TE = value; - return; + if ((_bits & 137438953472L) == 0) + { + _bits |= 137438953472L; + _headers._TE = value; + return true; + } + return false; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 549755813888L; - _headers._Translate = value; - return; + if ((_bits & 274877906944L) == 0) + { + _bits |= 274877906944L; + _headers._Translate = value; + return true; + } + return false; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4398046511104L; - _headers._AccessControlRequestMethod = value; - return; + if ((_bits & 2199023255552L) == 0) + { + _bits |= 2199023255552L; + _headers._AccessControlRequestMethod = value; + return true; + } + return false; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8796093022208L; - _headers._AccessControlRequestHeaders = value; - return; + if ((_bits & 4398046511104L) == 0) + { + _bits |= 4398046511104L; + _headers._AccessControlRequestHeaders = value; + return true; + } + return false; } } break; -} - - Unknown[key] = value; + } + + Unknown.Add(key, value); + // Return true, above will throw and exit for false + return true; } - protected override void AddValueFast(string key, StringValues value) + + protected override bool RemoveFast(string key) { - switch (key.Length) { case 13: { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~1L; + _headers._CacheControl = default(StringValues); + return true; } - _bits |= 1L; - _headers._CacheControl = value; - return; + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~65536L; + _headers._ContentRange = default(StringValues); + return true; } - _bits |= 131072L; - _headers._ContentRange = value; - return; + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~262144L; + _headers._LastModified = default(StringValues); + return true; } - _bits |= 524288L; - _headers._LastModified = value; - return; + return false; } - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~8388608L; + _headers._Authorization = default(StringValues); + return true; } - _bits |= 16777216L; - _headers._Authorization = value; - return; + return false; } - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~1073741824L; + _headers._IfNoneMatch = default(StringValues); + return true; } - _bits |= 2147483648L; - _headers._IfNoneMatch = value; - return; + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~2L; + _headers._Connection = default(StringValues); + return true; } - _bits |= 2L; - _headers._Connection = value; - return; + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~8L; + _headers._KeepAlive = default(StringValues); + return true; } - _bits |= 8L; - _headers._KeepAlive = value; - return; + return false; } - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~549755813888L; + _headers._UserAgent = default(StringValues); + return true; } - _bits |= 1099511627776L; - _headers._UserAgent = value; - return; + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~4L; + _headers._Date = default(StringValues); + return true; } - _bits |= 4L; - _headers._Date = value; - return; + return false; } - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~67108864L; + _headers._From = default(StringValues); + return true; } - _bits |= 134217728L; - _headers._From = value; - return; + return false; } - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~134217728L; + _headers._Host = default(StringValues); + return true; } - _bits |= 268435456L; - _headers._Host = value; - return; + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~16L; + _headers._Pragma = default(StringValues); + return true; } - _bits |= 16L; - _headers._Pragma = value; - return; + return false; } - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~524288L; + _headers._Accept = default(StringValues); + return true; } - _bits |= 1048576L; - _headers._Accept = value; - return; + return false; } - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~16777216L; + _headers._Cookie = default(StringValues); + return true; } - _bits |= 33554432L; - _headers._Cookie = value; - return; + return false; } - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~33554432L; + _headers._Expect = default(StringValues); + return true; } - _bits |= 67108864L; - _headers._Expect = value; - return; + return false; } - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~1099511627776L; + _headers._Origin = default(StringValues); + return true; } - _bits |= 2199023255552L; - _headers._Origin = value; - return; + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~32L; + _headers._Trailer = default(StringValues); + return true; } - _bits |= 32L; - _headers._Trailer = value; - return; + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~128L; + _headers._Upgrade = default(StringValues); + return true; } - _bits |= 128L; - _headers._Upgrade = value; - return; + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~512L; + _headers._Warning = default(StringValues); + return true; } - _bits |= 512L; - _headers._Warning = value; - return; + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~131072L; + _headers._Expires = default(StringValues); + return true; } - _bits |= 262144L; - _headers._Expires = value; - return; + return false; } - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~34359738368L; + _headers._Referer = default(StringValues); + return true; } - _bits |= 68719476736L; - _headers._Referer = value; - return; + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~64L; + _headers._TransferEncoding = default(StringValues); + return true; } - _bits |= 64L; - _headers._TransferEncoding = value; - return; + return false; } - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~536870912L; + _headers._IfModifiedSince = default(StringValues); + return true; } - _bits |= 1073741824L; - _headers._IfModifiedSince = value; - return; + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~256L; + _headers._Via = default(StringValues); + return true; } - _bits |= 256L; - _headers._Via = value; - return; + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~1024L; + _headers._Allow = default(StringValues); + return true; } - _bits |= 1024L; - _headers._Allow = value; - return; + return false; } - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 137438953472L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 137438953472L; - _headers._Range = value; - return; - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) + if ((_bits & 68719476736L) != 0) { - ThrowDuplicateKeyException(); - } - _bits |= 2048L; - _headers._ContentLength = value; - return; - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - ThrowDuplicateKeyException(); + _bits &= ~68719476736L; + _headers._Range = default(StringValues); + return true; } - _bits |= 2097152L; - _headers._AcceptCharset = value; - return; + return false; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~2048L; + _headers._ContentType = default(StringValues); + return true; } - _bits |= 4096L; - _headers._ContentType = value; - return; + return false; } - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~8589934592L; + _headers._MaxForwards = default(StringValues); + return true; } - _bits |= 17179869184L; - _headers._MaxForwards = value; - return; + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~4096L; + _headers._ContentEncoding = default(StringValues); + return true; } - _bits |= 8192L; - _headers._ContentEncoding = value; - return; + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~8192L; + _headers._ContentLanguage = default(StringValues); + return true; } - _bits |= 16384L; - _headers._ContentLanguage = value; - return; + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~16384L; + _headers._ContentLocation = default(StringValues); + return true; } - _bits |= 32768L; - _headers._ContentLocation = value; - return; + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~32768L; + _headers._ContentMD5 = default(StringValues); + return true; } - _bits |= 65536L; - _headers._ContentMD5 = value; - return; + return false; + } + } + break; + case 14: + { + if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if ((_bits & 1048576L) != 0) + { + _bits &= ~1048576L; + _headers._AcceptCharset = default(StringValues); + return true; + } + return false; + } + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) + { + _contentLength = null; + return true; + } + return false; } } break; - case 15: { if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~2097152L; + _headers._AcceptEncoding = default(StringValues); + return true; } - _bits |= 4194304L; - _headers._AcceptEncoding = value; - return; + return false; } - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~4194304L; + _headers._AcceptLanguage = default(StringValues); + return true; } - _bits |= 8388608L; - _headers._AcceptLanguage = value; - return; + return false; } } break; - case 8: { if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~268435456L; + _headers._IfMatch = default(StringValues); + return true; } - _bits |= 536870912L; - _headers._IfMatch = value; - return; + return false; } - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~2147483648L; + _headers._IfRange = default(StringValues); + return true; } - _bits |= 4294967296L; - _headers._IfRange = value; - return; + return false; } } break; - case 19: { if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~4294967296L; + _headers._IfUnmodifiedSince = default(StringValues); + return true; } - _bits |= 8589934592L; - _headers._IfUnmodifiedSince = value; - return; + return false; } - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~17179869184L; + _headers._ProxyAuthorization = default(StringValues); + return true; } - _bits |= 34359738368L; - _headers._ProxyAuthorization = value; - return; + return false; } } break; - case 2: { if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~137438953472L; + _headers._TE = default(StringValues); + return true; } - _bits |= 274877906944L; - _headers._TE = value; - return; + return false; } } break; - case 9: { if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~274877906944L; + _headers._Translate = default(StringValues); + return true; } - _bits |= 549755813888L; - _headers._Translate = value; - return; + return false; } } break; - case 29: { if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~2199023255552L; + _headers._AccessControlRequestMethod = default(StringValues); + return true; } - _bits |= 4398046511104L; - _headers._AccessControlRequestMethod = value; - return; + return false; } } break; - case 30: { if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { - ThrowDuplicateKeyException(); + _bits &= ~4398046511104L; + _headers._AccessControlRequestHeaders = default(StringValues); + return true; } - _bits |= 8796093022208L; - _headers._AccessControlRequestHeaders = value; - return; + return false; } } break; } - - Unknown.Add(key, value); + + return MaybeUnknown?.Remove(key) ?? false; } - protected override bool RemoveFast(string key) + + protected override void ClearFast() { - switch (key.Length) + MaybeUnknown?.Clear(); + _contentLength = null; + var tempBits = _bits; + _bits = 0; + if(FrameHeaders.BitCount(tempBits) > 12) { - case 13: - { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1L) != 0)) - { - _bits &= ~1L; - _headers._CacheControl = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 131072L) != 0)) - { - _bits &= ~131072L; - _headers._ContentRange = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 524288L) != 0)) - { - _bits &= ~524288L; - _headers._LastModified = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - _bits &= ~16777216L; - _headers._Authorization = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("If-None-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2147483648L) != 0)) - { - _bits &= ~2147483648L; - _headers._IfNoneMatch = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + _headers = default(HeaderReferences); + return; + } - case 10: - { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2L) != 0)) - { - _bits &= ~2L; - _headers._Connection = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8L) != 0)) - { - _bits &= ~8L; - _headers._KeepAlive = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("User-Agent".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1099511627776L) != 0)) - { - _bits &= ~1099511627776L; - _headers._UserAgent = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 524288L) != 0) + { + _headers._Accept = default(StringValues); + if((tempBits & ~524288L) == 0) + { + return; + } + tempBits &= ~524288L; + } - case 4: - { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4L) != 0)) - { - _bits &= ~4L; - _headers._Date = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("From".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 134217728L) != 0)) - { - _bits &= ~134217728L; - _headers._From = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Host".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 268435456L) != 0)) - { - _bits &= ~268435456L; - _headers._Host = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 134217728L) != 0) + { + _headers._Host = default(StringValues); + if((tempBits & ~134217728L) == 0) + { + return; + } + tempBits &= ~134217728L; + } - case 6: - { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16L) != 0)) - { - _bits &= ~16L; - _headers._Pragma = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Accept".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1048576L) != 0)) - { - _bits &= ~1048576L; - _headers._Accept = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 33554432L) != 0)) - { - _bits &= ~33554432L; - _headers._Cookie = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Expect".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 67108864L) != 0)) - { - _bits &= ~67108864L; - _headers._Expect = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2199023255552L) != 0)) - { - _bits &= ~2199023255552L; - _headers._Origin = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 549755813888L) != 0) + { + _headers._UserAgent = default(StringValues); + if((tempBits & ~549755813888L) == 0) + { + return; + } + tempBits &= ~549755813888L; + } - case 7: - { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32L) != 0)) - { - _bits &= ~32L; - _headers._Trailer = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 128L) != 0)) - { - _bits &= ~128L; - _headers._Upgrade = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 512L) != 0)) - { - _bits &= ~512L; - _headers._Warning = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 262144L) != 0)) - { - _bits &= ~262144L; - _headers._Expires = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Referer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 68719476736L) != 0)) - { - _bits &= ~68719476736L; - _headers._Referer = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 1L) != 0) + { + _headers._CacheControl = default(StringValues); + if((tempBits & ~1L) == 0) + { + return; + } + tempBits &= ~1L; + } - case 17: - { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 64L) != 0)) - { - _bits &= ~64L; - _headers._TransferEncoding = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("If-Modified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1073741824L) != 0)) - { - _bits &= ~1073741824L; - _headers._IfModifiedSince = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 2L) != 0) + { + _headers._Connection = default(StringValues); + if((tempBits & ~2L) == 0) + { + return; + } + tempBits &= ~2L; + } - case 3: - { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 256L) != 0)) - { - _bits &= ~256L; - _headers._Via = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 4L) != 0) + { + _headers._Date = default(StringValues); + if((tempBits & ~4L) == 0) + { + return; + } + tempBits &= ~4L; + } - case 5: - { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1024L) != 0)) - { - _bits &= ~1024L; - _headers._Allow = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 137438953472L) != 0)) - { - _bits &= ~137438953472L; - _headers._Range = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 8L) != 0) + { + _headers._KeepAlive = default(StringValues); + if((tempBits & ~8L) == 0) + { + return; + } + tempBits &= ~8L; + } - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - _bits &= ~2048L; - _headers._ContentLength = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Accept-Charset".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - _bits &= ~2097152L; - _headers._AcceptCharset = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; + if ((tempBits & 16L) != 0) + { + _headers._Pragma = default(StringValues); + if((tempBits & ~16L) == 0) + { + return; + } + tempBits &= ~16L; + } - case 12: - { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4096L) != 0)) - { - _bits &= ~4096L; - _headers._ContentType = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Max-Forwards".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 17179869184L) != 0)) - { - _bits &= ~17179869184L; - _headers._MaxForwards = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 16: - { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8192L) != 0)) - { - _bits &= ~8192L; - _headers._ContentEncoding = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16384L) != 0)) - { - _bits &= ~16384L; - _headers._ContentLanguage = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32768L) != 0)) - { - _bits &= ~32768L; - _headers._ContentLocation = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 11: - { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 65536L) != 0)) - { - _bits &= ~65536L; - _headers._ContentMD5 = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 15: - { - if ("Accept-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4194304L) != 0)) - { - _bits &= ~4194304L; - _headers._AcceptEncoding = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Accept-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8388608L) != 0)) - { - _bits &= ~8388608L; - _headers._AcceptLanguage = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 8: - { - if ("If-Match".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 536870912L) != 0)) - { - _bits &= ~536870912L; - _headers._IfMatch = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("If-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4294967296L) != 0)) - { - _bits &= ~4294967296L; - _headers._IfRange = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 19: - { - if ("If-Unmodified-Since".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8589934592L) != 0)) - { - _bits &= ~8589934592L; - _headers._IfUnmodifiedSince = StringValues.Empty; - return true; - } - else - { - return false; - } - } - - if ("Proxy-Authorization".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 34359738368L) != 0)) - { - _bits &= ~34359738368L; - _headers._ProxyAuthorization = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 2: - { - if ("TE".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 274877906944L) != 0)) - { - _bits &= ~274877906944L; - _headers._TE = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 9: - { - if ("Translate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 549755813888L) != 0)) - { - _bits &= ~549755813888L; - _headers._Translate = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 29: - { - if ("Access-Control-Request-Method".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4398046511104L) != 0)) - { - _bits &= ~4398046511104L; - _headers._AccessControlRequestMethod = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 30: - { - if ("Access-Control-Request-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8796093022208L) != 0)) - { - _bits &= ~8796093022208L; - _headers._AccessControlRequestHeaders = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - } - return MaybeUnknown?.Remove(key) ?? false; - } - protected override void ClearFast() - { - MaybeUnknown?.Clear(); - - if(FrameHeaders.BitCount(_bits) > 12) + if ((tempBits & 32L) != 0) { - _headers = default(HeaderReferences); - _bits = 0; - return; + _headers._Trailer = default(StringValues); + if((tempBits & ~32L) == 0) + { + return; + } + tempBits &= ~32L; } - if (((_bits & 1048576L) != 0)) + if ((tempBits & 64L) != 0) { - _headers._Accept = default(StringValues); - _bits &= ~1048576L; - if(_bits == 0) + _headers._TransferEncoding = default(StringValues); + if((tempBits & ~64L) == 0) { return; } + tempBits &= ~64L; } - if (((_bits & 268435456L) != 0)) + if ((tempBits & 128L) != 0) { - _headers._Host = default(StringValues); - _bits &= ~268435456L; - if(_bits == 0) + _headers._Upgrade = default(StringValues); + if((tempBits & ~128L) == 0) { return; } + tempBits &= ~128L; } - if (((_bits & 1099511627776L) != 0)) + if ((tempBits & 256L) != 0) { - _headers._UserAgent = default(StringValues); - _bits &= ~1099511627776L; - if(_bits == 0) + _headers._Via = default(StringValues); + if((tempBits & ~256L) == 0) { return; } + tempBits &= ~256L; } - if (((_bits & 1L) != 0)) + if ((tempBits & 512L) != 0) { - _headers._CacheControl = default(StringValues); - _bits &= ~1L; - if(_bits == 0) + _headers._Warning = default(StringValues); + if((tempBits & ~512L) == 0) { return; } + tempBits &= ~512L; } - if (((_bits & 2L) != 0)) + if ((tempBits & 1024L) != 0) { - _headers._Connection = default(StringValues); - _bits &= ~2L; - if(_bits == 0) + _headers._Allow = default(StringValues); + if((tempBits & ~1024L) == 0) { return; } + tempBits &= ~1024L; } - if (((_bits & 4L) != 0)) + if ((tempBits & 2048L) != 0) { - _headers._Date = default(StringValues); - _bits &= ~4L; - if(_bits == 0) + _headers._ContentType = default(StringValues); + if((tempBits & ~2048L) == 0) { return; } + tempBits &= ~2048L; } - if (((_bits & 8L) != 0)) + if ((tempBits & 4096L) != 0) { - _headers._KeepAlive = default(StringValues); - _bits &= ~8L; - if(_bits == 0) + _headers._ContentEncoding = default(StringValues); + if((tempBits & ~4096L) == 0) { return; } + tempBits &= ~4096L; } - if (((_bits & 16L) != 0)) + if ((tempBits & 8192L) != 0) { - _headers._Pragma = default(StringValues); - _bits &= ~16L; - if(_bits == 0) + _headers._ContentLanguage = default(StringValues); + if((tempBits & ~8192L) == 0) { return; } + tempBits &= ~8192L; } - if (((_bits & 32L) != 0)) + if ((tempBits & 16384L) != 0) { - _headers._Trailer = default(StringValues); - _bits &= ~32L; - if(_bits == 0) + _headers._ContentLocation = default(StringValues); + if((tempBits & ~16384L) == 0) { return; } + tempBits &= ~16384L; } - if (((_bits & 64L) != 0)) + if ((tempBits & 32768L) != 0) { - _headers._TransferEncoding = default(StringValues); - _bits &= ~64L; - if(_bits == 0) + _headers._ContentMD5 = default(StringValues); + if((tempBits & ~32768L) == 0) { return; } + tempBits &= ~32768L; } - if (((_bits & 128L) != 0)) + if ((tempBits & 65536L) != 0) { - _headers._Upgrade = default(StringValues); - _bits &= ~128L; - if(_bits == 0) + _headers._ContentRange = default(StringValues); + if((tempBits & ~65536L) == 0) { return; } + tempBits &= ~65536L; } - if (((_bits & 256L) != 0)) + if ((tempBits & 131072L) != 0) { - _headers._Via = default(StringValues); - _bits &= ~256L; - if(_bits == 0) + _headers._Expires = default(StringValues); + if((tempBits & ~131072L) == 0) { return; } + tempBits &= ~131072L; } - if (((_bits & 512L) != 0)) + if ((tempBits & 262144L) != 0) { - _headers._Warning = default(StringValues); - _bits &= ~512L; - if(_bits == 0) + _headers._LastModified = default(StringValues); + if((tempBits & ~262144L) == 0) { return; } + tempBits &= ~262144L; } - if (((_bits & 1024L) != 0)) + if ((tempBits & 1048576L) != 0) { - _headers._Allow = default(StringValues); - _bits &= ~1024L; - if(_bits == 0) + _headers._AcceptCharset = default(StringValues); + if((tempBits & ~1048576L) == 0) { return; } + tempBits &= ~1048576L; } - if (((_bits & 2048L) != 0)) + if ((tempBits & 2097152L) != 0) { - _headers._ContentLength = default(StringValues); - _bits &= ~2048L; - if(_bits == 0) + _headers._AcceptEncoding = default(StringValues); + if((tempBits & ~2097152L) == 0) { return; } + tempBits &= ~2097152L; } - if (((_bits & 4096L) != 0)) + if ((tempBits & 4194304L) != 0) { - _headers._ContentType = default(StringValues); - _bits &= ~4096L; - if(_bits == 0) + _headers._AcceptLanguage = default(StringValues); + if((tempBits & ~4194304L) == 0) { return; } + tempBits &= ~4194304L; } - if (((_bits & 8192L) != 0)) + if ((tempBits & 8388608L) != 0) { - _headers._ContentEncoding = default(StringValues); - _bits &= ~8192L; - if(_bits == 0) + _headers._Authorization = default(StringValues); + if((tempBits & ~8388608L) == 0) { return; } + tempBits &= ~8388608L; } - if (((_bits & 16384L) != 0)) + if ((tempBits & 16777216L) != 0) { - _headers._ContentLanguage = default(StringValues); - _bits &= ~16384L; - if(_bits == 0) + _headers._Cookie = default(StringValues); + if((tempBits & ~16777216L) == 0) { return; } + tempBits &= ~16777216L; } - if (((_bits & 32768L) != 0)) + if ((tempBits & 33554432L) != 0) { - _headers._ContentLocation = default(StringValues); - _bits &= ~32768L; - if(_bits == 0) + _headers._Expect = default(StringValues); + if((tempBits & ~33554432L) == 0) { return; } + tempBits &= ~33554432L; } - if (((_bits & 65536L) != 0)) + if ((tempBits & 67108864L) != 0) { - _headers._ContentMD5 = default(StringValues); - _bits &= ~65536L; - if(_bits == 0) + _headers._From = default(StringValues); + if((tempBits & ~67108864L) == 0) { return; } + tempBits &= ~67108864L; } - if (((_bits & 131072L) != 0)) + if ((tempBits & 268435456L) != 0) { - _headers._ContentRange = default(StringValues); - _bits &= ~131072L; - if(_bits == 0) + _headers._IfMatch = default(StringValues); + if((tempBits & ~268435456L) == 0) { return; } + tempBits &= ~268435456L; } - if (((_bits & 262144L) != 0)) + if ((tempBits & 536870912L) != 0) { - _headers._Expires = default(StringValues); - _bits &= ~262144L; - if(_bits == 0) + _headers._IfModifiedSince = default(StringValues); + if((tempBits & ~536870912L) == 0) { return; } + tempBits &= ~536870912L; } - if (((_bits & 524288L) != 0)) + if ((tempBits & 1073741824L) != 0) { - _headers._LastModified = default(StringValues); - _bits &= ~524288L; - if(_bits == 0) + _headers._IfNoneMatch = default(StringValues); + if((tempBits & ~1073741824L) == 0) { return; } + tempBits &= ~1073741824L; } - if (((_bits & 2097152L) != 0)) + if ((tempBits & 2147483648L) != 0) { - _headers._AcceptCharset = default(StringValues); - _bits &= ~2097152L; - if(_bits == 0) + _headers._IfRange = default(StringValues); + if((tempBits & ~2147483648L) == 0) { return; } + tempBits &= ~2147483648L; } - if (((_bits & 4194304L) != 0)) - { - _headers._AcceptEncoding = default(StringValues); - _bits &= ~4194304L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 8388608L) != 0)) - { - _headers._AcceptLanguage = default(StringValues); - _bits &= ~8388608L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 16777216L) != 0)) - { - _headers._Authorization = default(StringValues); - _bits &= ~16777216L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 33554432L) != 0)) - { - _headers._Cookie = default(StringValues); - _bits &= ~33554432L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 67108864L) != 0)) - { - _headers._Expect = default(StringValues); - _bits &= ~67108864L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 134217728L) != 0)) - { - _headers._From = default(StringValues); - _bits &= ~134217728L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 536870912L) != 0)) - { - _headers._IfMatch = default(StringValues); - _bits &= ~536870912L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 1073741824L) != 0)) - { - _headers._IfModifiedSince = default(StringValues); - _bits &= ~1073741824L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 2147483648L) != 0)) - { - _headers._IfNoneMatch = default(StringValues); - _bits &= ~2147483648L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 4294967296L) != 0)) - { - _headers._IfRange = default(StringValues); - _bits &= ~4294967296L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 8589934592L) != 0)) + if ((tempBits & 4294967296L) != 0) { _headers._IfUnmodifiedSince = default(StringValues); - _bits &= ~8589934592L; - if(_bits == 0) + if((tempBits & ~4294967296L) == 0) { return; } + tempBits &= ~4294967296L; } - if (((_bits & 17179869184L) != 0)) + if ((tempBits & 8589934592L) != 0) { _headers._MaxForwards = default(StringValues); - _bits &= ~17179869184L; - if(_bits == 0) + if((tempBits & ~8589934592L) == 0) { return; } + tempBits &= ~8589934592L; } - if (((_bits & 34359738368L) != 0)) + if ((tempBits & 17179869184L) != 0) { _headers._ProxyAuthorization = default(StringValues); - _bits &= ~34359738368L; - if(_bits == 0) + if((tempBits & ~17179869184L) == 0) { return; } + tempBits &= ~17179869184L; } - if (((_bits & 68719476736L) != 0)) + if ((tempBits & 34359738368L) != 0) { _headers._Referer = default(StringValues); - _bits &= ~68719476736L; - if(_bits == 0) + if((tempBits & ~34359738368L) == 0) { return; } + tempBits &= ~34359738368L; } - if (((_bits & 137438953472L) != 0)) + if ((tempBits & 68719476736L) != 0) { _headers._Range = default(StringValues); - _bits &= ~137438953472L; - if(_bits == 0) + if((tempBits & ~68719476736L) == 0) { return; } + tempBits &= ~68719476736L; } - if (((_bits & 274877906944L) != 0)) + if ((tempBits & 137438953472L) != 0) { _headers._TE = default(StringValues); - _bits &= ~274877906944L; - if(_bits == 0) + if((tempBits & ~137438953472L) == 0) { return; } + tempBits &= ~137438953472L; } - if (((_bits & 549755813888L) != 0)) + if ((tempBits & 274877906944L) != 0) { _headers._Translate = default(StringValues); - _bits &= ~549755813888L; - if(_bits == 0) + if((tempBits & ~274877906944L) == 0) { return; } + tempBits &= ~274877906944L; } - if (((_bits & 2199023255552L) != 0)) + if ((tempBits & 1099511627776L) != 0) { _headers._Origin = default(StringValues); - _bits &= ~2199023255552L; - if(_bits == 0) + if((tempBits & ~1099511627776L) == 0) { return; } + tempBits &= ~1099511627776L; } - if (((_bits & 4398046511104L) != 0)) + if ((tempBits & 2199023255552L) != 0) { _headers._AccessControlRequestMethod = default(StringValues); - _bits &= ~4398046511104L; - if(_bits == 0) + if((tempBits & ~2199023255552L) == 0) { return; } + tempBits &= ~2199023255552L; } - if (((_bits & 8796093022208L) != 0)) + if ((tempBits & 4398046511104L) != 0) { _headers._AccessControlRequestHeaders = default(StringValues); - _bits &= ~8796093022208L; - if(_bits == 0) + if((tempBits & ~4398046511104L) == 0) { return; } + tempBits &= ~4398046511104L; } } - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override bool CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) { - ThrowArgumentException(); + return false; } - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Cache-Control", _headers._CacheControl); ++arrayIndex; } - - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Connection", _headers._Connection); ++arrayIndex; } - - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Date", _headers._Date); ++arrayIndex; } - - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _headers._KeepAlive); ++arrayIndex; } - - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Pragma", _headers._Pragma); ++arrayIndex; } - - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Trailer", _headers._Trailer); ++arrayIndex; } - - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _headers._TransferEncoding); ++arrayIndex; } - - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Upgrade", _headers._Upgrade); ++arrayIndex; } - - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Via", _headers._Via); ++arrayIndex; } - - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Warning", _headers._Warning); ++arrayIndex; } - - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Allow", _headers._Allow); ++arrayIndex; } - - if (((_bits & 2048L) != 0)) - { - if (arrayIndex == array.Length) - { - ThrowArgumentException(); - } - - array[arrayIndex] = new KeyValuePair("Content-Length", _headers._ContentLength); - ++arrayIndex; - } - - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Type", _headers._ContentType); ++arrayIndex; } - - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _headers._ContentEncoding); ++arrayIndex; } - - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Language", _headers._ContentLanguage); ++arrayIndex; } - - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Location", _headers._ContentLocation); ++arrayIndex; } - - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-MD5", _headers._ContentMD5); ++arrayIndex; } - - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Range", _headers._ContentRange); ++arrayIndex; } - - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Expires", _headers._Expires); ++arrayIndex; } - - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Last-Modified", _headers._LastModified); ++arrayIndex; } - - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept", _headers._Accept); ++arrayIndex; } - - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Charset", _headers._AcceptCharset); ++arrayIndex; } - - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Encoding", _headers._AcceptEncoding); ++arrayIndex; } - - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Language", _headers._AcceptLanguage); ++arrayIndex; } - - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Authorization", _headers._Authorization); ++arrayIndex; } - - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Cookie", _headers._Cookie); ++arrayIndex; } - - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Expect", _headers._Expect); ++arrayIndex; } - - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("From", _headers._From); ++arrayIndex; } - - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Host", _headers._Host); ++arrayIndex; } - - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Match", _headers._IfMatch); ++arrayIndex; } - - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Modified-Since", _headers._IfModifiedSince); ++arrayIndex; } - - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-None-Match", _headers._IfNoneMatch); ++arrayIndex; } - - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Range", _headers._IfRange); ++arrayIndex; } - - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("If-Unmodified-Since", _headers._IfUnmodifiedSince); ++arrayIndex; } - - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Max-Forwards", _headers._MaxForwards); ++arrayIndex; } - - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Proxy-Authorization", _headers._ProxyAuthorization); ++arrayIndex; } - - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Referer", _headers._Referer); ++arrayIndex; } - - if (((_bits & 137438953472L) != 0)) + if ((_bits & 68719476736L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Range", _headers._Range); ++arrayIndex; } - - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("TE", _headers._TE); ++arrayIndex; } - - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Translate", _headers._Translate); ++arrayIndex; } - - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("User-Agent", _headers._UserAgent); ++arrayIndex; } - - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Origin", _headers._Origin); ++arrayIndex; } - - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Request-Method", _headers._AccessControlRequestMethod); ++arrayIndex; } - - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Request-Headers", _headers._AccessControlRequestHeaders); ++arrayIndex; } - + if (_contentLength.HasValue) + { + if (arrayIndex == array.Length) + { + return false; + } + array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_contentLength.Value)); + ++arrayIndex; + } ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + + return true; } @@ -4651,20 +3509,21 @@ public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + var stringValue = new StringValues(value); switch (keyLength) { case 6: { if ((((pUI[0] & 3755991007u) == 1162036033u) && ((pUS[2] & 57311u) == 21584u))) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { _headers._Accept = AppendValue(_headers._Accept, value); } else { - _bits |= 1048576L; - _headers._Accept = new StringValues(value); + _bits |= 524288L; + _headers._Accept = stringValue; } return; } @@ -4675,14 +3534,14 @@ public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string { if ((((pUI[0] & 3755991007u) == 1414745928u))) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { _headers._Host = AppendValue(_headers._Host, value); } else { - _bits |= 268435456L; - _headers._Host = new StringValues(value); + _bits |= 134217728L; + _headers._Host = stringValue; } return; } @@ -4693,14 +3552,14 @@ public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string { if ((((pUL[0] & 16131858680330051551uL) == 4992030374873092949uL) && ((pUS[4] & 57311u) == 21582u))) { - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 549755813888L) != 0) { _headers._UserAgent = AppendValue(_headers._UserAgent, value); } else { - _bits |= 1099511627776L; - _headers._UserAgent = new StringValues(value); + _bits |= 549755813888L; + _headers._UserAgent = stringValue; } return; } @@ -4708,91 +3567,87 @@ public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string break; } - + AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); } - - AppendNonPrimaryHeaders(keyBytes, keyOffset, keyLength, value); } - private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) { - string key; - fixed (byte* ptr = &keyBytes[keyOffset]) - { - var pUB = ptr; + var pUB = pKeyBytes; var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + var stringValue = new StringValues(value); switch (keyLength) { case 13: { if ((((pUL[0] & 16131893727263186911uL) == 5711458528024281411uL) && ((pUI[2] & 3755991007u) == 1330795598u) && ((pUB[12] & 223u) == 76u))) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _headers._CacheControl = AppendValue(_headers._CacheControl, value); } else { _bits |= 1L; - _headers._CacheControl = new StringValues(value); + _headers._CacheControl = stringValue; } return; } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196310866u) && ((pUB[12] & 223u) == 69u))) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { _headers._ContentRange = AppendValue(_headers._ContentRange, value); } else { - _bits |= 131072L; - _headers._ContentRange = new StringValues(value); + _bits |= 65536L; + _headers._ContentRange = stringValue; } return; } if ((((pUL[0] & 16131858680330051551uL) == 4922237774822850892uL) && ((pUI[2] & 3755991007u) == 1162430025u) && ((pUB[12] & 223u) == 68u))) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { _headers._LastModified = AppendValue(_headers._LastModified, value); } else { - _bits |= 524288L; - _headers._LastModified = new StringValues(value); + _bits |= 262144L; + _headers._LastModified = stringValue; } return; } if ((((pUL[0] & 16131858542891098079uL) == 6505821637182772545uL) && ((pUI[2] & 3755991007u) == 1330205761u) && ((pUB[12] & 223u) == 78u))) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { _headers._Authorization = AppendValue(_headers._Authorization, value); } else { - _bits |= 16777216L; - _headers._Authorization = new StringValues(value); + _bits |= 8388608L; + _headers._Authorization = stringValue; } return; } if ((((pUL[0] & 18437701552106889183uL) == 3262099607620765257uL) && ((pUI[2] & 3755991007u) == 1129595213u) && ((pUB[12] & 223u) == 72u))) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { _headers._IfNoneMatch = AppendValue(_headers._IfNoneMatch, value); } else { - _bits |= 2147483648L; - _headers._IfNoneMatch = new StringValues(value); + _bits |= 1073741824L; + _headers._IfNoneMatch = stringValue; } return; } @@ -4803,28 +3658,28 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16131858542891098079uL) == 5283922227757993795uL) && ((pUS[4] & 57311u) == 20047u))) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _headers._Connection = AppendValue(_headers._Connection, value); } else { _bits |= 2L; - _headers._Connection = new StringValues(value); + _headers._Connection = stringValue; } return; } if ((((pUL[0] & 16131858680330051551uL) == 5281668125874799947uL) && ((pUS[4] & 57311u) == 17750u))) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _headers._KeepAlive = AppendValue(_headers._KeepAlive, value); } else { _bits |= 8L; - _headers._KeepAlive = new StringValues(value); + _headers._KeepAlive = stringValue; } return; } @@ -4835,28 +3690,28 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUI[0] & 3755991007u) == 1163149636u))) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _headers._Date = AppendValue(_headers._Date, value); } else { _bits |= 4L; - _headers._Date = new StringValues(value); + _headers._Date = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1297044038u))) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { _headers._From = AppendValue(_headers._From, value); } else { - _bits |= 134217728L; - _headers._From = new StringValues(value); + _bits |= 67108864L; + _headers._From = stringValue; } return; } @@ -4867,56 +3722,56 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUI[0] & 3755991007u) == 1195463248u) && ((pUS[2] & 57311u) == 16717u))) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _headers._Pragma = AppendValue(_headers._Pragma, value); } else { _bits |= 16L; - _headers._Pragma = new StringValues(value); + _headers._Pragma = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1263488835u) && ((pUS[2] & 57311u) == 17737u))) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { _headers._Cookie = AppendValue(_headers._Cookie, value); } else { - _bits |= 33554432L; - _headers._Cookie = new StringValues(value); + _bits |= 16777216L; + _headers._Cookie = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1162893381u) && ((pUS[2] & 57311u) == 21571u))) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { _headers._Expect = AppendValue(_headers._Expect, value); } else { - _bits |= 67108864L; - _headers._Expect = new StringValues(value); + _bits |= 33554432L; + _headers._Expect = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1195987535u) && ((pUS[2] & 57311u) == 20041u))) { - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 1099511627776L) != 0) { _headers._Origin = AppendValue(_headers._Origin, value); } else { - _bits |= 2199023255552L; - _headers._Origin = new StringValues(value); + _bits |= 1099511627776L; + _headers._Origin = stringValue; } return; } @@ -4927,70 +3782,70 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUI[0] & 3755991007u) == 1229017684u) && ((pUS[2] & 57311u) == 17740u) && ((pUB[6] & 223u) == 82u))) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _headers._Trailer = AppendValue(_headers._Trailer, value); } else { _bits |= 32L; - _headers._Trailer = new StringValues(value); + _headers._Trailer = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1380405333u) && ((pUS[2] & 57311u) == 17473u) && ((pUB[6] & 223u) == 69u))) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _headers._Upgrade = AppendValue(_headers._Upgrade, value); } else { _bits |= 128L; - _headers._Upgrade = new StringValues(value); + _headers._Upgrade = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1314013527u) && ((pUS[2] & 57311u) == 20041u) && ((pUB[6] & 223u) == 71u))) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _headers._Warning = AppendValue(_headers._Warning, value); } else { _bits |= 512L; - _headers._Warning = new StringValues(value); + _headers._Warning = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1230002245u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 83u))) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { _headers._Expires = AppendValue(_headers._Expires, value); } else { - _bits |= 262144L; - _headers._Expires = new StringValues(value); + _bits |= 131072L; + _headers._Expires = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1162233170u) && ((pUS[2] & 57311u) == 17746u) && ((pUB[6] & 223u) == 82u))) { - if (((_bits & 68719476736L) != 0)) + if ((_bits & 34359738368L) != 0) { _headers._Referer = AppendValue(_headers._Referer, value); } else { - _bits |= 68719476736L; - _headers._Referer = new StringValues(value); + _bits |= 34359738368L; + _headers._Referer = stringValue; } return; } @@ -5001,28 +3856,28 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16131858542891098079uL) == 5928221808112259668uL) && ((pUL[1] & 16131858542891098111uL) == 5641115115480565037uL) && ((pUB[16] & 223u) == 71u))) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _headers._TransferEncoding = AppendValue(_headers._TransferEncoding, value); } else { _bits |= 64L; - _headers._TransferEncoding = new StringValues(value); + _headers._TransferEncoding = stringValue; } return; } if ((((pUL[0] & 16131858542893195231uL) == 5064654363342751305uL) && ((pUL[1] & 16131858543427968991uL) == 4849894470315165001uL) && ((pUB[16] & 223u) == 69u))) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { _headers._IfModifiedSince = AppendValue(_headers._IfModifiedSince, value); } else { - _bits |= 1073741824L; - _headers._IfModifiedSince = new StringValues(value); + _bits |= 536870912L; + _headers._IfModifiedSince = stringValue; } return; } @@ -5033,14 +3888,14 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUS[0] & 57311u) == 18774u) && ((pUB[2] & 223u) == 65u))) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _headers._Via = AppendValue(_headers._Via, value); } else { _bits |= 256L; - _headers._Via = new StringValues(value); + _headers._Via = stringValue; } return; } @@ -5051,92 +3906,60 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUI[0] & 3755991007u) == 1330400321u) && ((pUB[4] & 223u) == 87u))) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _headers._Allow = AppendValue(_headers._Allow, value); } else { _bits |= 1024L; - _headers._Allow = new StringValues(value); + _headers._Allow = stringValue; } return; } if ((((pUI[0] & 3755991007u) == 1196310866u) && ((pUB[4] & 223u) == 69u))) { - if (((_bits & 137438953472L) != 0)) + if ((_bits & 68719476736L) != 0) { _headers._Range = AppendValue(_headers._Range, value); } else { - _bits |= 137438953472L; - _headers._Range = new StringValues(value); + _bits |= 68719476736L; + _headers._Range = stringValue; } return; } } break; - case 14: + case 12: { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) { - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { - _headers._ContentLength = AppendValue(_headers._ContentLength, value); + _headers._ContentType = AppendValue(_headers._ContentType, value); } else { _bits |= 2048L; - _headers._ContentLength = new StringValues(value); - } - return; - } - - if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) - { - if (((_bits & 2097152L) != 0)) - { - _headers._AcceptCharset = AppendValue(_headers._AcceptCharset, value); - } - else - { - _bits |= 2097152L; - _headers._AcceptCharset = new StringValues(value); - } - return; - } - } - break; - - case 12: - { - if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1162893652u))) - { - if (((_bits & 4096L) != 0)) - { - _headers._ContentType = AppendValue(_headers._ContentType, value); - } - else - { - _bits |= 4096L; - _headers._ContentType = new StringValues(value); + _headers._ContentType = stringValue; } return; } if ((((pUL[0] & 16131858543427968991uL) == 6292178792217067853uL) && ((pUI[2] & 3755991007u) == 1396986433u))) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { _headers._MaxForwards = AppendValue(_headers._MaxForwards, value); } else { - _bits |= 17179869184L; - _headers._MaxForwards = new StringValues(value); + _bits |= 8589934592L; + _headers._MaxForwards = stringValue; } return; } @@ -5147,42 +3970,42 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5138124782612729413uL))) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { _headers._ContentEncoding = AppendValue(_headers._ContentEncoding, value); } else { - _bits |= 8192L; - _headers._ContentEncoding = new StringValues(value); + _bits |= 4096L; + _headers._ContentEncoding = stringValue; } return; } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 4992030546487820620uL))) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { _headers._ContentLanguage = AppendValue(_headers._ContentLanguage, value); } else { - _bits |= 16384L; - _headers._ContentLanguage = new StringValues(value); + _bits |= 8192L; + _headers._ContentLanguage = stringValue; } return; } if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUL[1] & 16131858542891098079uL) == 5642809484339531596uL))) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { _headers._ContentLocation = AppendValue(_headers._ContentLocation, value); } else { - _bits |= 32768L; - _headers._ContentLocation = new StringValues(value); + _bits |= 16384L; + _headers._ContentLocation = stringValue; } return; } @@ -5193,14 +4016,45 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUS[4] & 57311u) == 17485u) && ((pUB[10] & 255u) == 53u))) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { _headers._ContentMD5 = AppendValue(_headers._ContentMD5, value); } else { - _bits |= 65536L; - _headers._ContentMD5 = new StringValues(value); + _bits |= 32768L; + _headers._ContentMD5 = stringValue; + } + return; + } + } + break; + + case 14: + { + if ((((pUL[0] & 16140865742145839071uL) == 4840617878229304129uL) && ((pUI[2] & 3755991007u) == 1397899592u) && ((pUS[6] & 57311u) == 21573u))) + { + if ((_bits & 1048576L) != 0) + { + _headers._AcceptCharset = AppendValue(_headers._AcceptCharset, value); + } + else + { + _bits |= 1048576L; + _headers._AcceptCharset = stringValue; + } + return; + } + + if ((((pUL[0] & 18437701552104792031uL) == 3266321689424580419uL) && ((pUI[2] & 3755991007u) == 1196311884u) && ((pUS[6] & 57311u) == 18516u))) + { + if (_contentLength.HasValue) + { + ThrowMultipleContentLengthsException(); + } + else + { + _contentLength = ParseContentLength(value); } return; } @@ -5211,28 +4065,28 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16140865742145839071uL) == 4984733066305160001uL) && ((pUI[2] & 3755991007u) == 1146045262u) && ((pUS[6] & 57311u) == 20041u) && ((pUB[14] & 223u) == 71u))) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { _headers._AcceptEncoding = AppendValue(_headers._AcceptEncoding, value); } else { - _bits |= 4194304L; - _headers._AcceptEncoding = new StringValues(value); + _bits |= 2097152L; + _headers._AcceptEncoding = stringValue; } return; } if ((((pUL[0] & 16140865742145839071uL) == 5489136224570655553uL) && ((pUI[2] & 3755991007u) == 1430736449u) && ((pUS[6] & 57311u) == 18241u) && ((pUB[14] & 223u) == 69u))) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { _headers._AcceptLanguage = AppendValue(_headers._AcceptLanguage, value); } else { - _bits |= 8388608L; - _headers._AcceptLanguage = new StringValues(value); + _bits |= 4194304L; + _headers._AcceptLanguage = stringValue; } return; } @@ -5243,28 +4097,28 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16131858542893195231uL) == 5207098233614845513uL))) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { _headers._IfMatch = AppendValue(_headers._IfMatch, value); } else { - _bits |= 536870912L; - _headers._IfMatch = new StringValues(value); + _bits |= 268435456L; + _headers._IfMatch = stringValue; } return; } if ((((pUL[0] & 16131858542893195231uL) == 4992044754422023753uL))) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { _headers._IfRange = AppendValue(_headers._IfRange, value); } else { - _bits |= 4294967296L; - _headers._IfRange = new StringValues(value); + _bits |= 2147483648L; + _headers._IfRange = stringValue; } return; } @@ -5275,28 +4129,28 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16131858542893195231uL) == 4922237916571059785uL) && ((pUL[1] & 16131893727263186911uL) == 5283616559079179849uL) && ((pUS[8] & 57311u) == 17230u) && ((pUB[18] & 223u) == 69u))) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { _headers._IfUnmodifiedSince = AppendValue(_headers._IfUnmodifiedSince, value); } else { - _bits |= 8589934592L; - _headers._IfUnmodifiedSince = new StringValues(value); + _bits |= 4294967296L; + _headers._IfUnmodifiedSince = stringValue; } return; } if ((((pUL[0] & 16131893727263186911uL) == 6143241228466999888uL) && ((pUL[1] & 16131858542891098079uL) == 6071233043632179284uL) && ((pUS[8] & 57311u) == 20297u) && ((pUB[18] & 223u) == 78u))) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { _headers._ProxyAuthorization = AppendValue(_headers._ProxyAuthorization, value); } else { - _bits |= 34359738368L; - _headers._ProxyAuthorization = new StringValues(value); + _bits |= 17179869184L; + _headers._ProxyAuthorization = stringValue; } return; } @@ -5307,14 +4161,14 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUS[0] & 57311u) == 17748u))) { - if (((_bits & 274877906944L) != 0)) + if ((_bits & 137438953472L) != 0) { _headers._TE = AppendValue(_headers._TE, value); } else { - _bits |= 274877906944L; - _headers._TE = new StringValues(value); + _bits |= 137438953472L; + _headers._TE = stringValue; } return; } @@ -5325,14 +4179,14 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16131858542891098079uL) == 6071217693351039572uL) && ((pUB[8] & 223u) == 69u))) { - if (((_bits & 549755813888L) != 0)) + if ((_bits & 274877906944L) != 0) { _headers._Translate = AppendValue(_headers._Translate, value); } else { - _bits |= 549755813888L; - _headers._Translate = new StringValues(value); + _bits |= 274877906944L; + _headers._Translate = stringValue; } return; } @@ -5343,14 +4197,14 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5561193831494668613uL) && ((pUI[6] & 3755991007u) == 1330140229u) && ((pUB[28] & 223u) == 68u))) { - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 2199023255552L) != 0) { _headers._AccessControlRequestMethod = AppendValue(_headers._AccessControlRequestMethod, value); } else { - _bits |= 4398046511104L; - _headers._AccessControlRequestMethod = new StringValues(value); + _bits |= 2199023255552L; + _headers._AccessControlRequestMethod = stringValue; } return; } @@ -5361,14 +4215,14 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int { if ((((pUL[0] & 16140865742145839071uL) == 4840616791602578241uL) && ((pUL[1] & 16140865742145839071uL) == 5921472988629454415uL) && ((pUL[2] & 16140865742145839071uL) == 5200905861305028933uL) && ((pUI[6] & 3755991007u) == 1162101061u) && ((pUS[14] & 57311u) == 21330u))) { - if (((_bits & 8796093022208L) != 0)) + if ((_bits & 4398046511104L) != 0) { _headers._AccessControlRequestHeaders = AppendValue(_headers._AccessControlRequestHeaders, value); } else { - _bits |= 8796093022208L; - _headers._AccessControlRequestHeaders = new StringValues(value); + _bits |= 4398046511104L; + _headers._AccessControlRequestHeaders = stringValue; } return; } @@ -5376,22 +4230,9 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int break; } - - key = new string('\0', keyLength); - fixed(char *keyBuffer = key) - { - if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) - { - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); - } - } - - } - - StringValues existing; - Unknown.TryGetValue(key, out existing); - Unknown[key] = AppendValue(existing, value); + AppendUnknownHeaders(pKeyBytes, keyLength, value); } + private struct HeaderReferences { public StringValues _CacheControl; @@ -5405,7 +4246,6 @@ private struct HeaderReferences public StringValues _Via; public StringValues _Warning; public StringValues _Allow; - public StringValues _ContentLength; public StringValues _ContentType; public StringValues _ContentEncoding; public StringValues _ContentLanguage; @@ -5448,144 +4288,143 @@ public bool MoveNext() switch (_state) { - case 0: - goto state0; - - case 1: - goto state1; + case 0: + goto state0; - case 2: - goto state2; + case 1: + goto state1; - case 3: - goto state3; + case 2: + goto state2; - case 4: - goto state4; + case 3: + goto state3; - case 5: - goto state5; + case 4: + goto state4; - case 6: - goto state6; + case 5: + goto state5; - case 7: - goto state7; + case 6: + goto state6; - case 8: - goto state8; + case 7: + goto state7; - case 9: - goto state9; + case 8: + goto state8; - case 10: - goto state10; + case 9: + goto state9; - case 11: - goto state11; + case 10: + goto state10; - case 12: - goto state12; + case 11: + goto state11; - case 13: - goto state13; + case 12: + goto state12; - case 14: - goto state14; + case 13: + goto state13; - case 15: - goto state15; + case 14: + goto state14; - case 16: - goto state16; + case 15: + goto state15; - case 17: - goto state17; + case 16: + goto state16; - case 18: - goto state18; + case 17: + goto state17; - case 19: - goto state19; + case 18: + goto state18; - case 20: - goto state20; + case 19: + goto state19; - case 21: - goto state21; + case 20: + goto state20; - case 22: - goto state22; + case 21: + goto state21; - case 23: - goto state23; + case 22: + goto state22; - case 24: - goto state24; + case 23: + goto state23; - case 25: - goto state25; + case 24: + goto state24; - case 26: - goto state26; + case 25: + goto state25; - case 27: - goto state27; + case 26: + goto state26; - case 28: - goto state28; + case 27: + goto state27; - case 29: - goto state29; + case 28: + goto state28; - case 30: - goto state30; + case 29: + goto state29; - case 31: - goto state31; + case 30: + goto state30; - case 32: - goto state32; + case 31: + goto state31; - case 33: - goto state33; + case 32: + goto state32; - case 34: - goto state34; + case 33: + goto state33; - case 35: - goto state35; + case 34: + goto state34; - case 36: - goto state36; + case 35: + goto state35; - case 37: - goto state37; + case 36: + goto state36; - case 38: - goto state38; + case 37: + goto state37; - case 39: - goto state39; + case 38: + goto state38; - case 40: - goto state40; + case 39: + goto state39; - case 41: - goto state41; + case 40: + goto state40; - case 42: - goto state42; + case 41: + goto state41; - case 43: - goto state43; + case 42: + goto state42; + case 44: + goto state44; default: goto state_default; } state0: - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _current = new KeyValuePair("Cache-Control", _collection._headers._CacheControl); _state = 1; @@ -5593,7 +4432,7 @@ public bool MoveNext() } state1: - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _current = new KeyValuePair("Connection", _collection._headers._Connection); _state = 2; @@ -5601,7 +4440,7 @@ public bool MoveNext() } state2: - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _current = new KeyValuePair("Date", _collection._headers._Date); _state = 3; @@ -5609,7 +4448,7 @@ public bool MoveNext() } state3: - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _current = new KeyValuePair("Keep-Alive", _collection._headers._KeepAlive); _state = 4; @@ -5617,7 +4456,7 @@ public bool MoveNext() } state4: - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _current = new KeyValuePair("Pragma", _collection._headers._Pragma); _state = 5; @@ -5625,7 +4464,7 @@ public bool MoveNext() } state5: - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _current = new KeyValuePair("Trailer", _collection._headers._Trailer); _state = 6; @@ -5633,7 +4472,7 @@ public bool MoveNext() } state6: - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _current = new KeyValuePair("Transfer-Encoding", _collection._headers._TransferEncoding); _state = 7; @@ -5641,7 +4480,7 @@ public bool MoveNext() } state7: - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _current = new KeyValuePair("Upgrade", _collection._headers._Upgrade); _state = 8; @@ -5649,7 +4488,7 @@ public bool MoveNext() } state8: - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _current = new KeyValuePair("Via", _collection._headers._Via); _state = 9; @@ -5657,7 +4496,7 @@ public bool MoveNext() } state9: - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _current = new KeyValuePair("Warning", _collection._headers._Warning); _state = 10; @@ -5665,7 +4504,7 @@ public bool MoveNext() } state10: - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _current = new KeyValuePair("Allow", _collection._headers._Allow); _state = 11; @@ -5673,269 +4512,268 @@ public bool MoveNext() } state11: - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { - _current = new KeyValuePair("Content-Length", _collection._headers._ContentLength); + _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); _state = 12; return true; } state12: - if (((_bits & 4096L) != 0)) + if ((_bits & 4096L) != 0) { - _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); + _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); _state = 13; return true; } state13: - if (((_bits & 8192L) != 0)) + if ((_bits & 8192L) != 0) { - _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); + _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); _state = 14; return true; } state14: - if (((_bits & 16384L) != 0)) + if ((_bits & 16384L) != 0) { - _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); + _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); _state = 15; return true; } state15: - if (((_bits & 32768L) != 0)) + if ((_bits & 32768L) != 0) { - _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); + _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); _state = 16; return true; } state16: - if (((_bits & 65536L) != 0)) + if ((_bits & 65536L) != 0) { - _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); + _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); _state = 17; return true; } state17: - if (((_bits & 131072L) != 0)) + if ((_bits & 131072L) != 0) { - _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); + _current = new KeyValuePair("Expires", _collection._headers._Expires); _state = 18; return true; } state18: - if (((_bits & 262144L) != 0)) + if ((_bits & 262144L) != 0) { - _current = new KeyValuePair("Expires", _collection._headers._Expires); + _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); _state = 19; return true; } state19: - if (((_bits & 524288L) != 0)) + if ((_bits & 524288L) != 0) { - _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); + _current = new KeyValuePair("Accept", _collection._headers._Accept); _state = 20; return true; } state20: - if (((_bits & 1048576L) != 0)) + if ((_bits & 1048576L) != 0) { - _current = new KeyValuePair("Accept", _collection._headers._Accept); + _current = new KeyValuePair("Accept-Charset", _collection._headers._AcceptCharset); _state = 21; return true; } state21: - if (((_bits & 2097152L) != 0)) + if ((_bits & 2097152L) != 0) { - _current = new KeyValuePair("Accept-Charset", _collection._headers._AcceptCharset); + _current = new KeyValuePair("Accept-Encoding", _collection._headers._AcceptEncoding); _state = 22; return true; } state22: - if (((_bits & 4194304L) != 0)) + if ((_bits & 4194304L) != 0) { - _current = new KeyValuePair("Accept-Encoding", _collection._headers._AcceptEncoding); + _current = new KeyValuePair("Accept-Language", _collection._headers._AcceptLanguage); _state = 23; return true; } state23: - if (((_bits & 8388608L) != 0)) + if ((_bits & 8388608L) != 0) { - _current = new KeyValuePair("Accept-Language", _collection._headers._AcceptLanguage); + _current = new KeyValuePair("Authorization", _collection._headers._Authorization); _state = 24; return true; } state24: - if (((_bits & 16777216L) != 0)) + if ((_bits & 16777216L) != 0) { - _current = new KeyValuePair("Authorization", _collection._headers._Authorization); + _current = new KeyValuePair("Cookie", _collection._headers._Cookie); _state = 25; return true; } state25: - if (((_bits & 33554432L) != 0)) + if ((_bits & 33554432L) != 0) { - _current = new KeyValuePair("Cookie", _collection._headers._Cookie); + _current = new KeyValuePair("Expect", _collection._headers._Expect); _state = 26; return true; } state26: - if (((_bits & 67108864L) != 0)) + if ((_bits & 67108864L) != 0) { - _current = new KeyValuePair("Expect", _collection._headers._Expect); + _current = new KeyValuePair("From", _collection._headers._From); _state = 27; return true; } state27: - if (((_bits & 134217728L) != 0)) + if ((_bits & 134217728L) != 0) { - _current = new KeyValuePair("From", _collection._headers._From); + _current = new KeyValuePair("Host", _collection._headers._Host); _state = 28; return true; } state28: - if (((_bits & 268435456L) != 0)) + if ((_bits & 268435456L) != 0) { - _current = new KeyValuePair("Host", _collection._headers._Host); + _current = new KeyValuePair("If-Match", _collection._headers._IfMatch); _state = 29; return true; } state29: - if (((_bits & 536870912L) != 0)) + if ((_bits & 536870912L) != 0) { - _current = new KeyValuePair("If-Match", _collection._headers._IfMatch); + _current = new KeyValuePair("If-Modified-Since", _collection._headers._IfModifiedSince); _state = 30; return true; } state30: - if (((_bits & 1073741824L) != 0)) + if ((_bits & 1073741824L) != 0) { - _current = new KeyValuePair("If-Modified-Since", _collection._headers._IfModifiedSince); + _current = new KeyValuePair("If-None-Match", _collection._headers._IfNoneMatch); _state = 31; return true; } state31: - if (((_bits & 2147483648L) != 0)) + if ((_bits & 2147483648L) != 0) { - _current = new KeyValuePair("If-None-Match", _collection._headers._IfNoneMatch); + _current = new KeyValuePair("If-Range", _collection._headers._IfRange); _state = 32; return true; } state32: - if (((_bits & 4294967296L) != 0)) + if ((_bits & 4294967296L) != 0) { - _current = new KeyValuePair("If-Range", _collection._headers._IfRange); + _current = new KeyValuePair("If-Unmodified-Since", _collection._headers._IfUnmodifiedSince); _state = 33; return true; } state33: - if (((_bits & 8589934592L) != 0)) + if ((_bits & 8589934592L) != 0) { - _current = new KeyValuePair("If-Unmodified-Since", _collection._headers._IfUnmodifiedSince); + _current = new KeyValuePair("Max-Forwards", _collection._headers._MaxForwards); _state = 34; return true; } state34: - if (((_bits & 17179869184L) != 0)) + if ((_bits & 17179869184L) != 0) { - _current = new KeyValuePair("Max-Forwards", _collection._headers._MaxForwards); + _current = new KeyValuePair("Proxy-Authorization", _collection._headers._ProxyAuthorization); _state = 35; return true; } state35: - if (((_bits & 34359738368L) != 0)) + if ((_bits & 34359738368L) != 0) { - _current = new KeyValuePair("Proxy-Authorization", _collection._headers._ProxyAuthorization); + _current = new KeyValuePair("Referer", _collection._headers._Referer); _state = 36; return true; } state36: - if (((_bits & 68719476736L) != 0)) + if ((_bits & 68719476736L) != 0) { - _current = new KeyValuePair("Referer", _collection._headers._Referer); + _current = new KeyValuePair("Range", _collection._headers._Range); _state = 37; return true; } state37: - if (((_bits & 137438953472L) != 0)) + if ((_bits & 137438953472L) != 0) { - _current = new KeyValuePair("Range", _collection._headers._Range); + _current = new KeyValuePair("TE", _collection._headers._TE); _state = 38; return true; } state38: - if (((_bits & 274877906944L) != 0)) + if ((_bits & 274877906944L) != 0) { - _current = new KeyValuePair("TE", _collection._headers._TE); + _current = new KeyValuePair("Translate", _collection._headers._Translate); _state = 39; return true; } state39: - if (((_bits & 549755813888L) != 0)) + if ((_bits & 549755813888L) != 0) { - _current = new KeyValuePair("Translate", _collection._headers._Translate); + _current = new KeyValuePair("User-Agent", _collection._headers._UserAgent); _state = 40; return true; } state40: - if (((_bits & 1099511627776L) != 0)) + if ((_bits & 1099511627776L) != 0) { - _current = new KeyValuePair("User-Agent", _collection._headers._UserAgent); + _current = new KeyValuePair("Origin", _collection._headers._Origin); _state = 41; return true; } state41: - if (((_bits & 2199023255552L) != 0)) + if ((_bits & 2199023255552L) != 0) { - _current = new KeyValuePair("Origin", _collection._headers._Origin); + _current = new KeyValuePair("Access-Control-Request-Method", _collection._headers._AccessControlRequestMethod); _state = 42; return true; } state42: - if (((_bits & 4398046511104L) != 0)) + if ((_bits & 4398046511104L) != 0) { - _current = new KeyValuePair("Access-Control-Request-Method", _collection._headers._AccessControlRequestMethod); + _current = new KeyValuePair("Access-Control-Request-Headers", _collection._headers._AccessControlRequestHeaders); _state = 43; return true; } - state43: - if (((_bits & 8796093022208L) != 0)) + state44: + if (_collection._contentLength.HasValue) { - _current = new KeyValuePair("Access-Control-Request-Headers", _collection._headers._AccessControlRequestHeaders); - _state = 44; + _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _state = 45; return true; } - state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { @@ -5952,7 +4790,7 @@ public partial class FrameResponseHeaders { private static byte[] _headerBytes = new byte[] { - 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32, + 13,10,67,97,99,104,101,45,67,111,110,116,114,111,108,58,32,13,10,67,111,110,110,101,99,116,105,111,110,58,32,13,10,68,97,116,101,58,32,13,10,75,101,101,112,45,65,108,105,118,101,58,32,13,10,80,114,97,103,109,97,58,32,13,10,84,114,97,105,108,101,114,58,32,13,10,84,114,97,110,115,102,101,114,45,69,110,99,111,100,105,110,103,58,32,13,10,85,112,103,114,97,100,101,58,32,13,10,86,105,97,58,32,13,10,87,97,114,110,105,110,103,58,32,13,10,65,108,108,111,119,58,32,13,10,67,111,110,116,101,110,116,45,84,121,112,101,58,32,13,10,67,111,110,116,101,110,116,45,69,110,99,111,100,105,110,103,58,32,13,10,67,111,110,116,101,110,116,45,76,97,110,103,117,97,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,111,99,97,116,105,111,110,58,32,13,10,67,111,110,116,101,110,116,45,77,68,53,58,32,13,10,67,111,110,116,101,110,116,45,82,97,110,103,101,58,32,13,10,69,120,112,105,114,101,115,58,32,13,10,76,97,115,116,45,77,111,100,105,102,105,101,100,58,32,13,10,65,99,99,101,112,116,45,82,97,110,103,101,115,58,32,13,10,65,103,101,58,32,13,10,69,84,97,103,58,32,13,10,76,111,99,97,116,105,111,110,58,32,13,10,80,114,111,120,121,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,82,101,116,114,121,45,65,102,116,101,114,58,32,13,10,83,101,114,118,101,114,58,32,13,10,83,101,116,45,67,111,111,107,105,101,58,32,13,10,86,97,114,121,58,32,13,10,87,87,87,45,65,117,116,104,101,110,116,105,99,97,116,101,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,67,114,101,100,101,110,116,105,97,108,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,77,101,116,104,111,100,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,65,108,108,111,119,45,79,114,105,103,105,110,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,69,120,112,111,115,101,45,72,101,97,100,101,114,115,58,32,13,10,65,99,99,101,115,115,45,67,111,110,116,114,111,108,45,77,97,120,45,65,103,101,58,32,13,10,67,111,110,116,101,110,116,45,76,101,110,103,116,104,58,32, }; private long _bits = 0; @@ -5962,11 +4800,12 @@ public StringValues HeaderCacheControl { get { - if (((_bits & 1L) != 0)) + StringValues value; + if ((_bits & 1L) != 0) { - return _headers._CacheControl; + value = _headers._CacheControl; } - return StringValues.Empty; + return value; } set { @@ -5978,11 +4817,12 @@ public StringValues HeaderConnection { get { - if (((_bits & 2L) != 0)) + StringValues value; + if ((_bits & 2L) != 0) { - return _headers._Connection; + value = _headers._Connection; } - return StringValues.Empty; + return value; } set { @@ -5995,11 +4835,12 @@ public StringValues HeaderDate { get { - if (((_bits & 4L) != 0)) + StringValues value; + if ((_bits & 4L) != 0) { - return _headers._Date; + value = _headers._Date; } - return StringValues.Empty; + return value; } set { @@ -6012,11 +4853,12 @@ public StringValues HeaderKeepAlive { get { - if (((_bits & 8L) != 0)) + StringValues value; + if ((_bits & 8L) != 0) { - return _headers._KeepAlive; + value = _headers._KeepAlive; } - return StringValues.Empty; + return value; } set { @@ -6028,11 +4870,12 @@ public StringValues HeaderPragma { get { - if (((_bits & 16L) != 0)) + StringValues value; + if ((_bits & 16L) != 0) { - return _headers._Pragma; + value = _headers._Pragma; } - return StringValues.Empty; + return value; } set { @@ -6044,11 +4887,12 @@ public StringValues HeaderTrailer { get { - if (((_bits & 32L) != 0)) + StringValues value; + if ((_bits & 32L) != 0) { - return _headers._Trailer; + value = _headers._Trailer; } - return StringValues.Empty; + return value; } set { @@ -6060,11 +4904,12 @@ public StringValues HeaderTransferEncoding { get { - if (((_bits & 64L) != 0)) + StringValues value; + if ((_bits & 64L) != 0) { - return _headers._TransferEncoding; + value = _headers._TransferEncoding; } - return StringValues.Empty; + return value; } set { @@ -6077,11 +4922,12 @@ public StringValues HeaderUpgrade { get { - if (((_bits & 128L) != 0)) + StringValues value; + if ((_bits & 128L) != 0) { - return _headers._Upgrade; + value = _headers._Upgrade; } - return StringValues.Empty; + return value; } set { @@ -6093,11 +4939,12 @@ public StringValues HeaderVia { get { - if (((_bits & 256L) != 0)) + StringValues value; + if ((_bits & 256L) != 0) { - return _headers._Via; + value = _headers._Via; } - return StringValues.Empty; + return value; } set { @@ -6109,11 +4956,12 @@ public StringValues HeaderWarning { get { - if (((_bits & 512L) != 0)) + StringValues value; + if ((_bits & 512L) != 0) { - return _headers._Warning; + value = _headers._Warning; } - return StringValues.Empty; + return value; } set { @@ -6125,11 +4973,12 @@ public StringValues HeaderAllow { get { - if (((_bits & 1024L) != 0)) + StringValues value; + if ((_bits & 1024L) != 0) { - return _headers._Allow; + value = _headers._Allow; } - return StringValues.Empty; + return value; } set { @@ -6137,37 +4986,20 @@ public StringValues HeaderAllow _headers._Allow = value; } } - public StringValues HeaderContentLength - { - get - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - return StringValues.Empty; - } - set - { - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = null; - } - } public StringValues HeaderContentType { get { - if (((_bits & 4096L) != 0)) + StringValues value; + if ((_bits & 2048L) != 0) { - return _headers._ContentType; + value = _headers._ContentType; } - return StringValues.Empty; + return value; } set { - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; } } @@ -6175,15 +5007,16 @@ public StringValues HeaderContentEncoding { get { - if (((_bits & 8192L) != 0)) + StringValues value; + if ((_bits & 4096L) != 0) { - return _headers._ContentEncoding; + value = _headers._ContentEncoding; } - return StringValues.Empty; + return value; } set { - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; } } @@ -6191,15 +5024,16 @@ public StringValues HeaderContentLanguage { get { - if (((_bits & 16384L) != 0)) + StringValues value; + if ((_bits & 8192L) != 0) { - return _headers._ContentLanguage; + value = _headers._ContentLanguage; } - return StringValues.Empty; + return value; } set { - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; } } @@ -6207,15 +5041,16 @@ public StringValues HeaderContentLocation { get { - if (((_bits & 32768L) != 0)) + StringValues value; + if ((_bits & 16384L) != 0) { - return _headers._ContentLocation; + value = _headers._ContentLocation; } - return StringValues.Empty; + return value; } set { - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; } } @@ -6223,15 +5058,16 @@ public StringValues HeaderContentMD5 { get { - if (((_bits & 65536L) != 0)) + StringValues value; + if ((_bits & 32768L) != 0) { - return _headers._ContentMD5; + value = _headers._ContentMD5; } - return StringValues.Empty; + return value; } set { - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; } } @@ -6239,15 +5075,16 @@ public StringValues HeaderContentRange { get { - if (((_bits & 131072L) != 0)) + StringValues value; + if ((_bits & 65536L) != 0) { - return _headers._ContentRange; + value = _headers._ContentRange; } - return StringValues.Empty; + return value; } set { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; } } @@ -6255,15 +5092,16 @@ public StringValues HeaderExpires { get { - if (((_bits & 262144L) != 0)) + StringValues value; + if ((_bits & 131072L) != 0) { - return _headers._Expires; + value = _headers._Expires; } - return StringValues.Empty; + return value; } set { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; } } @@ -6271,15 +5109,16 @@ public StringValues HeaderLastModified { get { - if (((_bits & 524288L) != 0)) + StringValues value; + if ((_bits & 262144L) != 0) { - return _headers._LastModified; + value = _headers._LastModified; } - return StringValues.Empty; + return value; } set { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; } } @@ -6287,15 +5126,16 @@ public StringValues HeaderAcceptRanges { get { - if (((_bits & 1048576L) != 0)) + StringValues value; + if ((_bits & 524288L) != 0) { - return _headers._AcceptRanges; + value = _headers._AcceptRanges; } - return StringValues.Empty; + return value; } set { - _bits |= 1048576L; + _bits |= 524288L; _headers._AcceptRanges = value; } } @@ -6303,15 +5143,16 @@ public StringValues HeaderAge { get { - if (((_bits & 2097152L) != 0)) + StringValues value; + if ((_bits & 1048576L) != 0) { - return _headers._Age; + value = _headers._Age; } - return StringValues.Empty; + return value; } set { - _bits |= 2097152L; + _bits |= 1048576L; _headers._Age = value; } } @@ -6319,15 +5160,16 @@ public StringValues HeaderETag { get { - if (((_bits & 4194304L) != 0)) + StringValues value; + if ((_bits & 2097152L) != 0) { - return _headers._ETag; + value = _headers._ETag; } - return StringValues.Empty; + return value; } set { - _bits |= 4194304L; + _bits |= 2097152L; _headers._ETag = value; } } @@ -6335,15 +5177,16 @@ public StringValues HeaderLocation { get { - if (((_bits & 8388608L) != 0)) + StringValues value; + if ((_bits & 4194304L) != 0) { - return _headers._Location; + value = _headers._Location; } - return StringValues.Empty; + return value; } set { - _bits |= 8388608L; + _bits |= 4194304L; _headers._Location = value; } } @@ -6351,15 +5194,16 @@ public StringValues HeaderProxyAuthenticate { get { - if (((_bits & 16777216L) != 0)) + StringValues value; + if ((_bits & 8388608L) != 0) { - return _headers._ProxyAuthenticate; + value = _headers._ProxyAuthenticate; } - return StringValues.Empty; + return value; } set { - _bits |= 16777216L; + _bits |= 8388608L; _headers._ProxyAuthenticate = value; } } @@ -6367,15 +5211,16 @@ public StringValues HeaderRetryAfter { get { - if (((_bits & 33554432L) != 0)) + StringValues value; + if ((_bits & 16777216L) != 0) { - return _headers._RetryAfter; + value = _headers._RetryAfter; } - return StringValues.Empty; + return value; } set { - _bits |= 33554432L; + _bits |= 16777216L; _headers._RetryAfter = value; } } @@ -6383,15 +5228,16 @@ public StringValues HeaderServer { get { - if (((_bits & 67108864L) != 0)) + StringValues value; + if ((_bits & 33554432L) != 0) { - return _headers._Server; + value = _headers._Server; } - return StringValues.Empty; + return value; } set { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Server = value; _headers._rawServer = null; } @@ -6400,15 +5246,16 @@ public StringValues HeaderSetCookie { get { - if (((_bits & 134217728L) != 0)) + StringValues value; + if ((_bits & 67108864L) != 0) { - return _headers._SetCookie; + value = _headers._SetCookie; } - return StringValues.Empty; + return value; } set { - _bits |= 134217728L; + _bits |= 67108864L; _headers._SetCookie = value; } } @@ -6416,15 +5263,16 @@ public StringValues HeaderVary { get { - if (((_bits & 268435456L) != 0)) + StringValues value; + if ((_bits & 134217728L) != 0) { - return _headers._Vary; + value = _headers._Vary; } - return StringValues.Empty; + return value; } set { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Vary = value; } } @@ -6432,15 +5280,16 @@ public StringValues HeaderWWWAuthenticate { get { - if (((_bits & 536870912L) != 0)) + StringValues value; + if ((_bits & 268435456L) != 0) { - return _headers._WWWAuthenticate; + value = _headers._WWWAuthenticate; } - return StringValues.Empty; + return value; } set { - _bits |= 536870912L; + _bits |= 268435456L; _headers._WWWAuthenticate = value; } } @@ -6448,15 +5297,16 @@ public StringValues HeaderAccessControlAllowCredentials { get { - if (((_bits & 1073741824L) != 0)) + StringValues value; + if ((_bits & 536870912L) != 0) { - return _headers._AccessControlAllowCredentials; + value = _headers._AccessControlAllowCredentials; } - return StringValues.Empty; + return value; } set { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._AccessControlAllowCredentials = value; } } @@ -6464,15 +5314,16 @@ public StringValues HeaderAccessControlAllowHeaders { get { - if (((_bits & 2147483648L) != 0)) + StringValues value; + if ((_bits & 1073741824L) != 0) { - return _headers._AccessControlAllowHeaders; + value = _headers._AccessControlAllowHeaders; } - return StringValues.Empty; + return value; } set { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._AccessControlAllowHeaders = value; } } @@ -6480,620 +5331,116 @@ public StringValues HeaderAccessControlAllowMethods { get { - if (((_bits & 4294967296L) != 0)) + StringValues value; + if ((_bits & 2147483648L) != 0) { - return _headers._AccessControlAllowMethods; + value = _headers._AccessControlAllowMethods; } - return StringValues.Empty; + return value; } set { - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._AccessControlAllowMethods = value; } } - public StringValues HeaderAccessControlAllowOrigin - { - get - { - if (((_bits & 8589934592L) != 0)) - { - return _headers._AccessControlAllowOrigin; - } - return StringValues.Empty; - } - set - { - _bits |= 8589934592L; - _headers._AccessControlAllowOrigin = value; - } - } - public StringValues HeaderAccessControlExposeHeaders - { - get - { - if (((_bits & 17179869184L) != 0)) - { - return _headers._AccessControlExposeHeaders; - } - return StringValues.Empty; - } - set - { - _bits |= 17179869184L; - _headers._AccessControlExposeHeaders = value; - } - } - public StringValues HeaderAccessControlMaxAge - { - get - { - if (((_bits & 34359738368L) != 0)) - { - return _headers._AccessControlMaxAge; - } - return StringValues.Empty; - } - set - { - _bits |= 34359738368L; - _headers._AccessControlMaxAge = value; - } - } - - public void SetRawConnection(StringValues value, byte[] raw) - { - _bits |= 2L; - _headers._Connection = value; - _headers._rawConnection = raw; - } - public void SetRawDate(StringValues value, byte[] raw) - { - _bits |= 4L; - _headers._Date = value; - _headers._rawDate = raw; - } - public void SetRawTransferEncoding(StringValues value, byte[] raw) - { - _bits |= 64L; - _headers._TransferEncoding = value; - _headers._rawTransferEncoding = raw; - } - public void SetRawContentLength(StringValues value, byte[] raw) - { - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = raw; - } - public void SetRawServer(StringValues value, byte[] raw) - { - _bits |= 67108864L; - _headers._Server = value; - _headers._rawServer = raw; - } - protected override int GetCountFast() - { - return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); - } - protected override StringValues GetValueFast(string key) - { - switch (key.Length) - { - case 13: - { - if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1L) != 0)) - { - return _headers._CacheControl; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 131072L) != 0)) - { - return _headers._ContentRange; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 524288L) != 0)) - { - return _headers._LastModified; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1048576L) != 0)) - { - return _headers._AcceptRanges; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 10: - { - if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2L) != 0)) - { - return _headers._Connection; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8L) != 0)) - { - return _headers._KeepAlive; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 134217728L) != 0)) - { - return _headers._SetCookie; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 4: - { - if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4L) != 0)) - { - return _headers._Date; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4194304L) != 0)) - { - return _headers._ETag; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 268435456L) != 0)) - { - return _headers._Vary; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 6: - { - if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16L) != 0)) - { - return _headers._Pragma; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 67108864L) != 0)) - { - return _headers._Server; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 7: - { - if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32L) != 0)) - { - return _headers._Trailer; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 128L) != 0)) - { - return _headers._Upgrade; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 512L) != 0)) - { - return _headers._Warning; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 262144L) != 0)) - { - return _headers._Expires; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 17: - { - if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 64L) != 0)) - { - return _headers._TransferEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 3: - { - if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 256L) != 0)) - { - return _headers._Via; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2097152L) != 0)) - { - return _headers._Age; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 5: - { - if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1024L) != 0)) - { - return _headers._Allow; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - return _headers._ContentLength; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 12: - { - if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4096L) != 0)) - { - return _headers._ContentType; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 16: - { - if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8192L) != 0)) - { - return _headers._ContentEncoding; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16384L) != 0)) - { - return _headers._ContentLanguage; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 32768L) != 0)) - { - return _headers._ContentLocation; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 536870912L) != 0)) - { - return _headers._WWWAuthenticate; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 11: - { - if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 65536L) != 0)) - { - return _headers._ContentMD5; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 33554432L) != 0)) - { - return _headers._RetryAfter; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 8: - { - if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8388608L) != 0)) - { - return _headers._Location; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 18: - { - if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 16777216L) != 0)) - { - return _headers._ProxyAuthenticate; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 32: - { - if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 1073741824L) != 0)) - { - return _headers._AccessControlAllowCredentials; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 28: - { - if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2147483648L) != 0)) - { - return _headers._AccessControlAllowHeaders; - } - else - { - ThrowKeyNotFoundException(); - } - } - - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 4294967296L) != 0)) - { - return _headers._AccessControlAllowMethods; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 27: - { - if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 8589934592L) != 0)) - { - return _headers._AccessControlAllowOrigin; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 29: - { - if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 17179869184L) != 0)) - { - return _headers._AccessControlExposeHeaders; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; - - case 22: - { - if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 34359738368L) != 0)) - { - return _headers._AccessControlMaxAge; - } - else - { - ThrowKeyNotFoundException(); - } - } - } - break; -} - if (MaybeUnknown == null) + public StringValues HeaderAccessControlAllowOrigin + { + get + { + StringValues value; + if ((_bits & 4294967296L) != 0) + { + value = _headers._AccessControlAllowOrigin; + } + return value; + } + set + { + _bits |= 4294967296L; + _headers._AccessControlAllowOrigin = value; + } + } + public StringValues HeaderAccessControlExposeHeaders + { + get + { + StringValues value; + if ((_bits & 8589934592L) != 0) + { + value = _headers._AccessControlExposeHeaders; + } + return value; + } + set + { + _bits |= 8589934592L; + _headers._AccessControlExposeHeaders = value; + } + } + public StringValues HeaderAccessControlMaxAge + { + get + { + StringValues value; + if ((_bits & 17179869184L) != 0) + { + value = _headers._AccessControlMaxAge; + } + return value; + } + set + { + _bits |= 17179869184L; + _headers._AccessControlMaxAge = value; + } + } + public StringValues HeaderContentLength + { + get + { + StringValues value; + if (_contentLength.HasValue) + { + value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + } + return value; + } + set { - ThrowKeyNotFoundException(); + _contentLength = ParseContentLength(value); } - return MaybeUnknown[key]; } + + public void SetRawConnection(StringValues value, byte[] raw) + { + _bits |= 2L; + _headers._Connection = value; + _headers._rawConnection = raw; + } + public void SetRawDate(StringValues value, byte[] raw) + { + _bits |= 4L; + _headers._Date = value; + _headers._rawDate = raw; + } + public void SetRawTransferEncoding(StringValues value, byte[] raw) + { + _bits |= 64L; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = raw; + } + public void SetRawServer(StringValues value, byte[] raw) + { + _bits |= 33554432L; + _headers._Server = value; + _headers._rawServer = raw; + } + protected override int GetCountFast() + { + return (_contentLength.HasValue ? 1 : 0 ) + BitCount(_bits) + (MaybeUnknown?.Count ?? 0); + } + protected override bool TryGetValueFast(string key, out StringValues value) { switch (key.Length) @@ -7102,585 +5449,407 @@ protected override bool TryGetValueFast(string key, out StringValues value) { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { value = _headers._CacheControl; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { value = _headers._ContentRange; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { value = _headers._LastModified; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { value = _headers._AcceptRanges; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { value = _headers._Connection; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { value = _headers._KeepAlive; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { value = _headers._SetCookie; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { value = _headers._Date; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { value = _headers._ETag; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { value = _headers._Vary; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { value = _headers._Pragma; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { value = _headers._Server; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { value = _headers._Trailer; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { value = _headers._Upgrade; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { value = _headers._Warning; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { value = _headers._Expires; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { value = _headers._TransferEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { value = _headers._Via; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { value = _headers._Age; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { value = _headers._Allow; return true; } - else - { - value = StringValues.Empty; - return false; - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - value = _headers._ContentLength; - return true; - } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { value = _headers._ContentType; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { value = _headers._ContentEncoding; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { value = _headers._ContentLanguage; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { value = _headers._ContentLocation; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { value = _headers._WWWAuthenticate; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { value = _headers._ContentMD5; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { value = _headers._RetryAfter; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { value = _headers._Location; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { value = _headers._ProxyAuthenticate; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { value = _headers._AccessControlAllowCredentials; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { value = _headers._AccessControlAllowHeaders; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { value = _headers._AccessControlAllowMethods; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { value = _headers._AccessControlAllowOrigin; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { value = _headers._AccessControlExposeHeaders; return true; } - else - { - value = StringValues.Empty; - return false; - } + return false; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { value = _headers._AccessControlMaxAge; return true; } - else + return false; + } + } + break; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) { - value = StringValues.Empty; - return false; + value = HeaderUtilities.FormatInt64(_contentLength.Value); + return true; } + return false; } } break; -} - value = StringValues.Empty; + } + return MaybeUnknown?.TryGetValue(key, out value) ?? false; } + protected override void SetValueFast(string key, StringValues value) { ValidateHeaderCharacters(value); @@ -7694,30 +5863,26 @@ protected override void SetValueFast(string key, StringValues value) _headers._CacheControl = value; return; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 131072L; + _bits |= 65536L; _headers._ContentRange = value; return; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 524288L; + _bits |= 262144L; _headers._LastModified = value; return; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1048576L; + _bits |= 524288L; _headers._AcceptRanges = value; return; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7727,23 +5892,20 @@ protected override void SetValueFast(string key, StringValues value) _headers._rawConnection = null; return; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 8L; _headers._KeepAlive = value; return; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 134217728L; + _bits |= 67108864L; _headers._SetCookie = value; return; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7753,23 +5915,20 @@ protected override void SetValueFast(string key, StringValues value) _headers._rawDate = null; return; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4194304L; + _bits |= 2097152L; _headers._ETag = value; return; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 268435456L; + _bits |= 134217728L; _headers._Vary = value; return; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7778,17 +5937,15 @@ protected override void SetValueFast(string key, StringValues value) _headers._Pragma = value; return; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 67108864L; + _bits |= 33554432L; _headers._Server = value; _headers._rawServer = null; return; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7797,30 +5954,26 @@ protected override void SetValueFast(string key, StringValues value) _headers._Trailer = value; return; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 128L; _headers._Upgrade = value; return; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { _bits |= 512L; _headers._Warning = value; return; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 262144L; + _bits |= 131072L; _headers._Expires = value; return; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7832,7 +5985,6 @@ protected override void SetValueFast(string key, StringValues value) } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7841,16 +5993,14 @@ protected override void SetValueFast(string key, StringValues value) _headers._Via = value; return; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2097152L; + _bits |= 1048576L; _headers._Age = value; return; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) @@ -7861,169 +6011,151 @@ protected override void SetValueFast(string key, StringValues value) } } break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = null; - return; - } - } - break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4096L; + _bits |= 2048L; _headers._ContentType = value; return; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8192L; + _bits |= 4096L; _headers._ContentEncoding = value; return; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16384L; + _bits |= 8192L; _headers._ContentLanguage = value; return; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 32768L; + _bits |= 16384L; _headers._ContentLocation = value; return; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 536870912L; + _bits |= 268435456L; _headers._WWWAuthenticate = value; return; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 65536L; + _bits |= 32768L; _headers._ContentMD5 = value; return; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 33554432L; + _bits |= 16777216L; _headers._RetryAfter = value; return; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8388608L; + _bits |= 4194304L; _headers._Location = value; return; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 16777216L; + _bits |= 8388608L; _headers._ProxyAuthenticate = value; return; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 1073741824L; + _bits |= 536870912L; _headers._AccessControlAllowCredentials = value; return; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 2147483648L; + _bits |= 1073741824L; _headers._AccessControlAllowHeaders = value; return; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 4294967296L; + _bits |= 2147483648L; _headers._AccessControlAllowMethods = value; return; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 8589934592L; + _bits |= 4294967296L; _headers._AccessControlAllowOrigin = value; return; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 17179869184L; + _bits |= 8589934592L; _headers._AccessControlExposeHeaders = value; return; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - _bits |= 34359738368L; + _bits |= 17179869184L; _headers._AccessControlMaxAge = value; return; } } break; -} - ValidateHeaderCharacters(key); - Unknown[key] = value; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + _contentLength = ParseContentLength(value.ToString()); + return; + } + } + break; + } + + SetValueUnknown(key, value); } - protected override void AddValueFast(string key, StringValues value) + + protected override bool AddValueFast(string key, StringValues value) { ValidateHeaderCharacters(value); switch (key.Length) @@ -8032,483 +6164,449 @@ protected override void AddValueFast(string key, StringValues value) { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1L; + _headers._CacheControl = value; + return true; } - _bits |= 1L; - _headers._CacheControl = value; - return; + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 65536L; + _headers._ContentRange = value; + return true; } - _bits |= 131072L; - _headers._ContentRange = value; - return; + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 262144L; + _headers._LastModified = value; + return true; } - _bits |= 524288L; - _headers._LastModified = value; - return; + return false; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 524288L; + _headers._AcceptRanges = value; + return true; } - _bits |= 1048576L; - _headers._AcceptRanges = value; - return; + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2L; + _headers._Connection = value; + _headers._rawConnection = null; + return true; } - _bits |= 2L; - _headers._Connection = value; - _headers._rawConnection = null; - return; + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8L; + _headers._KeepAlive = value; + return true; } - _bits |= 8L; - _headers._KeepAlive = value; - return; + return false; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 67108864L; + _headers._SetCookie = value; + return true; } - _bits |= 134217728L; - _headers._SetCookie = value; - return; + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4L; + _headers._Date = value; + _headers._rawDate = null; + return true; } - _bits |= 4L; - _headers._Date = value; - _headers._rawDate = null; - return; + return false; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2097152L; + _headers._ETag = value; + return true; } - _bits |= 4194304L; - _headers._ETag = value; - return; + return false; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 134217728L; + _headers._Vary = value; + return true; } - _bits |= 268435456L; - _headers._Vary = value; - return; + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 16L; + _headers._Pragma = value; + return true; } - _bits |= 16L; - _headers._Pragma = value; - return; + return false; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 33554432L; + _headers._Server = value; + _headers._rawServer = null; + return true; } - _bits |= 67108864L; - _headers._Server = value; - _headers._rawServer = null; - return; + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 32L; + _headers._Trailer = value; + return true; } - _bits |= 32L; - _headers._Trailer = value; - return; + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 128L; + _headers._Upgrade = value; + return true; } - _bits |= 128L; - _headers._Upgrade = value; - return; + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 512L; + _headers._Warning = value; + return true; } - _bits |= 512L; - _headers._Warning = value; - return; + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 131072L; + _headers._Expires = value; + return true; } - _bits |= 262144L; - _headers._Expires = value; - return; + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 64L; + _headers._TransferEncoding = value; + _headers._rawTransferEncoding = null; + return true; } - _bits |= 64L; - _headers._TransferEncoding = value; - _headers._rawTransferEncoding = null; - return; + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 256L; + _headers._Via = value; + return true; } - _bits |= 256L; - _headers._Via = value; - return; + return false; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1048576L; + _headers._Age = value; + return true; } - _bits |= 2097152L; - _headers._Age = value; - return; + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) - { - ThrowDuplicateKeyException(); - } - _bits |= 1024L; - _headers._Allow = value; - return; - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) + if ((_bits & 1024L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1024L; + _headers._Allow = value; + return true; } - _contentLength = ParseContentLength(value); - _bits |= 2048L; - _headers._ContentLength = value; - _headers._rawContentLength = null; - return; + return false; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2048L; + _headers._ContentType = value; + return true; } - _bits |= 4096L; - _headers._ContentType = value; - return; + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4096L; + _headers._ContentEncoding = value; + return true; } - _bits |= 8192L; - _headers._ContentEncoding = value; - return; + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8192L; + _headers._ContentLanguage = value; + return true; } - _bits |= 16384L; - _headers._ContentLanguage = value; - return; + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 16384L; + _headers._ContentLocation = value; + return true; } - _bits |= 32768L; - _headers._ContentLocation = value; - return; + return false; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 268435456L; + _headers._WWWAuthenticate = value; + return true; } - _bits |= 536870912L; - _headers._WWWAuthenticate = value; - return; + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 32768L; + _headers._ContentMD5 = value; + return true; } - _bits |= 65536L; - _headers._ContentMD5 = value; - return; + return false; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 16777216L; + _headers._RetryAfter = value; + return true; } - _bits |= 33554432L; - _headers._RetryAfter = value; - return; + return false; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4194304L; + _headers._Location = value; + return true; } - _bits |= 8388608L; - _headers._Location = value; - return; + return false; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8388608L; + _headers._ProxyAuthenticate = value; + return true; } - _bits |= 16777216L; - _headers._ProxyAuthenticate = value; - return; + return false; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 536870912L; + _headers._AccessControlAllowCredentials = value; + return true; } - _bits |= 1073741824L; - _headers._AccessControlAllowCredentials = value; - return; + return false; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 1073741824L; + _headers._AccessControlAllowHeaders = value; + return true; } - _bits |= 2147483648L; - _headers._AccessControlAllowHeaders = value; - return; + return false; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 2147483648L; + _headers._AccessControlAllowMethods = value; + return true; } - _bits |= 4294967296L; - _headers._AccessControlAllowMethods = value; - return; + return false; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 4294967296L; + _headers._AccessControlAllowOrigin = value; + return true; } - _bits |= 8589934592L; - _headers._AccessControlAllowOrigin = value; - return; + return false; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 8589934592L; + _headers._AccessControlExposeHeaders = value; + return true; } - _bits |= 17179869184L; - _headers._AccessControlExposeHeaders = value; - return; + return false; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) == 0) { - ThrowDuplicateKeyException(); + _bits |= 17179869184L; + _headers._AccessControlMaxAge = value; + return true; } - _bits |= 34359738368L; - _headers._AccessControlMaxAge = value; - return; + return false; + } + } + break; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (!_contentLength.HasValue) + { + _contentLength = ParseContentLength(value); + return true; + } + return false; } } break; } + ValidateHeaderCharacters(key); Unknown.Add(key, value); + // Return true, above will throw and exit for false + return true; } + protected override bool RemoveFast(string key) { switch (key.Length) @@ -8517,1374 +6615,1151 @@ protected override bool RemoveFast(string key) { if ("Cache-Control".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _bits &= ~1L; - _headers._CacheControl = StringValues.Empty; + _headers._CacheControl = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Range".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { - _bits &= ~131072L; - _headers._ContentRange = StringValues.Empty; + _bits &= ~65536L; + _headers._ContentRange = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Last-Modified".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { - _bits &= ~524288L; - _headers._LastModified = StringValues.Empty; + _bits &= ~262144L; + _headers._LastModified = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Accept-Ranges".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { - _bits &= ~1048576L; - _headers._AcceptRanges = StringValues.Empty; + _bits &= ~524288L; + _headers._AcceptRanges = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 10: { if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _bits &= ~2L; - _headers._Connection = StringValues.Empty; + _headers._Connection = default(StringValues); _headers._rawConnection = null; return true; } - else - { - return false; - } + return false; } - if ("Keep-Alive".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _bits &= ~8L; - _headers._KeepAlive = StringValues.Empty; + _headers._KeepAlive = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Set-Cookie".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { - _bits &= ~134217728L; - _headers._SetCookie = StringValues.Empty; + _bits &= ~67108864L; + _headers._SetCookie = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 4: { if ("Date".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _bits &= ~4L; - _headers._Date = StringValues.Empty; + _headers._Date = default(StringValues); _headers._rawDate = null; return true; } - else - { - return false; - } + return false; } - if ("ETag".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { - _bits &= ~4194304L; - _headers._ETag = StringValues.Empty; + _bits &= ~2097152L; + _headers._ETag = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Vary".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { - _bits &= ~268435456L; - _headers._Vary = StringValues.Empty; + _bits &= ~134217728L; + _headers._Vary = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 6: { if ("Pragma".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _bits &= ~16L; - _headers._Pragma = StringValues.Empty; + _headers._Pragma = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Server".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { - _bits &= ~67108864L; - _headers._Server = StringValues.Empty; + _bits &= ~33554432L; + _headers._Server = default(StringValues); _headers._rawServer = null; return true; } - else - { - return false; - } + return false; } } break; - case 7: { if ("Trailer".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _bits &= ~32L; - _headers._Trailer = StringValues.Empty; + _headers._Trailer = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Upgrade".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _bits &= ~128L; - _headers._Upgrade = StringValues.Empty; + _headers._Upgrade = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Warning".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _bits &= ~512L; - _headers._Warning = StringValues.Empty; + _headers._Warning = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Expires".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { - _bits &= ~262144L; - _headers._Expires = StringValues.Empty; + _bits &= ~131072L; + _headers._Expires = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 17: { if ("Transfer-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _bits &= ~64L; - _headers._TransferEncoding = StringValues.Empty; + _headers._TransferEncoding = default(StringValues); _headers._rawTransferEncoding = null; return true; } - else - { - return false; - } + return false; } } break; - case 3: { if ("Via".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _bits &= ~256L; - _headers._Via = StringValues.Empty; + _headers._Via = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { - _bits &= ~2097152L; - _headers._Age = StringValues.Empty; + _bits &= ~1048576L; + _headers._Age = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 5: { if ("Allow".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _bits &= ~1024L; - _headers._Allow = StringValues.Empty; - return true; - } - else - { - return false; - } - } - } - break; - - case 14: - { - if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) - { - if (((_bits & 2048L) != 0)) - { - _contentLength = null; - _bits &= ~2048L; - _headers._ContentLength = StringValues.Empty; - _headers._rawContentLength = null; + _headers._Allow = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 12: { if ("Content-Type".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { - _bits &= ~4096L; - _headers._ContentType = StringValues.Empty; + _bits &= ~2048L; + _headers._ContentType = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 16: { if ("Content-Encoding".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { - _bits &= ~8192L; - _headers._ContentEncoding = StringValues.Empty; + _bits &= ~4096L; + _headers._ContentEncoding = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Language".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { - _bits &= ~16384L; - _headers._ContentLanguage = StringValues.Empty; + _bits &= ~8192L; + _headers._ContentLanguage = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Content-Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { - _bits &= ~32768L; - _headers._ContentLocation = StringValues.Empty; + _bits &= ~16384L; + _headers._ContentLocation = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("WWW-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { - _bits &= ~536870912L; - _headers._WWWAuthenticate = StringValues.Empty; + _bits &= ~268435456L; + _headers._WWWAuthenticate = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 11: { if ("Content-MD5".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { - _bits &= ~65536L; - _headers._ContentMD5 = StringValues.Empty; + _bits &= ~32768L; + _headers._ContentMD5 = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Retry-After".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { - _bits &= ~33554432L; - _headers._RetryAfter = StringValues.Empty; + _bits &= ~16777216L; + _headers._RetryAfter = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 8: { if ("Location".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { - _bits &= ~8388608L; - _headers._Location = StringValues.Empty; + _bits &= ~4194304L; + _headers._Location = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 18: { if ("Proxy-Authenticate".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { - _bits &= ~16777216L; - _headers._ProxyAuthenticate = StringValues.Empty; + _bits &= ~8388608L; + _headers._ProxyAuthenticate = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 32: { if ("Access-Control-Allow-Credentials".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { - _bits &= ~1073741824L; - _headers._AccessControlAllowCredentials = StringValues.Empty; + _bits &= ~536870912L; + _headers._AccessControlAllowCredentials = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 28: { if ("Access-Control-Allow-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { - _bits &= ~2147483648L; - _headers._AccessControlAllowHeaders = StringValues.Empty; + _bits &= ~1073741824L; + _headers._AccessControlAllowHeaders = default(StringValues); return true; } - else - { - return false; - } + return false; } - if ("Access-Control-Allow-Methods".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { - _bits &= ~4294967296L; - _headers._AccessControlAllowMethods = StringValues.Empty; + _bits &= ~2147483648L; + _headers._AccessControlAllowMethods = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 27: { if ("Access-Control-Allow-Origin".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { - _bits &= ~8589934592L; - _headers._AccessControlAllowOrigin = StringValues.Empty; + _bits &= ~4294967296L; + _headers._AccessControlAllowOrigin = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 29: { if ("Access-Control-Expose-Headers".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { - _bits &= ~17179869184L; - _headers._AccessControlExposeHeaders = StringValues.Empty; + _bits &= ~8589934592L; + _headers._AccessControlExposeHeaders = default(StringValues); return true; } - else - { - return false; - } + return false; } } break; - case 22: { if ("Access-Control-Max-Age".Equals(key, StringComparison.OrdinalIgnoreCase)) { - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { - _bits &= ~34359738368L; - _headers._AccessControlMaxAge = StringValues.Empty; + _bits &= ~17179869184L; + _headers._AccessControlMaxAge = default(StringValues); return true; } - else + return false; + } + } + break; + case 14: + { + if ("Content-Length".Equals(key, StringComparison.OrdinalIgnoreCase)) + { + if (_contentLength.HasValue) { - return false; + _contentLength = null; + return true; } + return false; } } break; } + return MaybeUnknown?.Remove(key) ?? false; } + protected override void ClearFast() - { + { MaybeUnknown?.Clear(); _contentLength = null; - if(FrameHeaders.BitCount(_bits) > 12) + var tempBits = _bits; + _bits = 0; + if(FrameHeaders.BitCount(tempBits) > 12) { _headers = default(HeaderReferences); - _bits = 0; return; } - if (((_bits & 2L) != 0)) + if ((tempBits & 2L) != 0) { _headers._Connection = default(StringValues); - _bits &= ~2L; - if(_bits == 0) + if((tempBits & ~2L) == 0) { return; } + tempBits &= ~2L; } - if (((_bits & 4L) != 0)) + if ((tempBits & 4L) != 0) { _headers._Date = default(StringValues); - _bits &= ~4L; - if(_bits == 0) - { - return; - } - } - - if (((_bits & 2048L) != 0)) - { - _headers._ContentLength = default(StringValues); - _bits &= ~2048L; - if(_bits == 0) + if((tempBits & ~4L) == 0) { return; } + tempBits &= ~4L; } - if (((_bits & 4096L) != 0)) + if ((tempBits & 2048L) != 0) { _headers._ContentType = default(StringValues); - _bits &= ~4096L; - if(_bits == 0) + if((tempBits & ~2048L) == 0) { return; } + tempBits &= ~2048L; } - if (((_bits & 67108864L) != 0)) + if ((tempBits & 33554432L) != 0) { _headers._Server = default(StringValues); - _bits &= ~67108864L; - if(_bits == 0) + if((tempBits & ~33554432L) == 0) { return; } + tempBits &= ~33554432L; } - if (((_bits & 1L) != 0)) + if ((tempBits & 1L) != 0) { _headers._CacheControl = default(StringValues); - _bits &= ~1L; - if(_bits == 0) + if((tempBits & ~1L) == 0) { return; } + tempBits &= ~1L; } - if (((_bits & 8L) != 0)) + if ((tempBits & 8L) != 0) { _headers._KeepAlive = default(StringValues); - _bits &= ~8L; - if(_bits == 0) + if((tempBits & ~8L) == 0) { return; } + tempBits &= ~8L; } - if (((_bits & 16L) != 0)) + if ((tempBits & 16L) != 0) { _headers._Pragma = default(StringValues); - _bits &= ~16L; - if(_bits == 0) + if((tempBits & ~16L) == 0) { return; } + tempBits &= ~16L; } - if (((_bits & 32L) != 0)) + if ((tempBits & 32L) != 0) { _headers._Trailer = default(StringValues); - _bits &= ~32L; - if(_bits == 0) + if((tempBits & ~32L) == 0) { return; } + tempBits &= ~32L; } - if (((_bits & 64L) != 0)) + if ((tempBits & 64L) != 0) { _headers._TransferEncoding = default(StringValues); - _bits &= ~64L; - if(_bits == 0) + if((tempBits & ~64L) == 0) { return; } + tempBits &= ~64L; } - if (((_bits & 128L) != 0)) + if ((tempBits & 128L) != 0) { _headers._Upgrade = default(StringValues); - _bits &= ~128L; - if(_bits == 0) + if((tempBits & ~128L) == 0) { return; } + tempBits &= ~128L; } - if (((_bits & 256L) != 0)) + if ((tempBits & 256L) != 0) { _headers._Via = default(StringValues); - _bits &= ~256L; - if(_bits == 0) + if((tempBits & ~256L) == 0) { return; } + tempBits &= ~256L; } - if (((_bits & 512L) != 0)) + if ((tempBits & 512L) != 0) { _headers._Warning = default(StringValues); - _bits &= ~512L; - if(_bits == 0) + if((tempBits & ~512L) == 0) { return; } + tempBits &= ~512L; } - if (((_bits & 1024L) != 0)) + if ((tempBits & 1024L) != 0) { _headers._Allow = default(StringValues); - _bits &= ~1024L; - if(_bits == 0) + if((tempBits & ~1024L) == 0) { return; } + tempBits &= ~1024L; } - if (((_bits & 8192L) != 0)) + if ((tempBits & 4096L) != 0) { _headers._ContentEncoding = default(StringValues); - _bits &= ~8192L; - if(_bits == 0) + if((tempBits & ~4096L) == 0) { return; } + tempBits &= ~4096L; } - if (((_bits & 16384L) != 0)) + if ((tempBits & 8192L) != 0) { _headers._ContentLanguage = default(StringValues); - _bits &= ~16384L; - if(_bits == 0) + if((tempBits & ~8192L) == 0) { return; } + tempBits &= ~8192L; } - if (((_bits & 32768L) != 0)) + if ((tempBits & 16384L) != 0) { _headers._ContentLocation = default(StringValues); - _bits &= ~32768L; - if(_bits == 0) + if((tempBits & ~16384L) == 0) { return; } + tempBits &= ~16384L; } - if (((_bits & 65536L) != 0)) + if ((tempBits & 32768L) != 0) { _headers._ContentMD5 = default(StringValues); - _bits &= ~65536L; - if(_bits == 0) + if((tempBits & ~32768L) == 0) { return; } + tempBits &= ~32768L; } - if (((_bits & 131072L) != 0)) + if ((tempBits & 65536L) != 0) { _headers._ContentRange = default(StringValues); - _bits &= ~131072L; - if(_bits == 0) + if((tempBits & ~65536L) == 0) { return; } + tempBits &= ~65536L; } - if (((_bits & 262144L) != 0)) + if ((tempBits & 131072L) != 0) { _headers._Expires = default(StringValues); - _bits &= ~262144L; - if(_bits == 0) + if((tempBits & ~131072L) == 0) { return; } + tempBits &= ~131072L; } - if (((_bits & 524288L) != 0)) + if ((tempBits & 262144L) != 0) { _headers._LastModified = default(StringValues); - _bits &= ~524288L; - if(_bits == 0) + if((tempBits & ~262144L) == 0) { return; } + tempBits &= ~262144L; } - if (((_bits & 1048576L) != 0)) + if ((tempBits & 524288L) != 0) { _headers._AcceptRanges = default(StringValues); - _bits &= ~1048576L; - if(_bits == 0) + if((tempBits & ~524288L) == 0) { return; } + tempBits &= ~524288L; } - if (((_bits & 2097152L) != 0)) + if ((tempBits & 1048576L) != 0) { _headers._Age = default(StringValues); - _bits &= ~2097152L; - if(_bits == 0) + if((tempBits & ~1048576L) == 0) { return; } + tempBits &= ~1048576L; } - if (((_bits & 4194304L) != 0)) + if ((tempBits & 2097152L) != 0) { _headers._ETag = default(StringValues); - _bits &= ~4194304L; - if(_bits == 0) + if((tempBits & ~2097152L) == 0) { return; } + tempBits &= ~2097152L; } - if (((_bits & 8388608L) != 0)) + if ((tempBits & 4194304L) != 0) { _headers._Location = default(StringValues); - _bits &= ~8388608L; - if(_bits == 0) + if((tempBits & ~4194304L) == 0) { return; } + tempBits &= ~4194304L; } - if (((_bits & 16777216L) != 0)) + if ((tempBits & 8388608L) != 0) { _headers._ProxyAuthenticate = default(StringValues); - _bits &= ~16777216L; - if(_bits == 0) + if((tempBits & ~8388608L) == 0) { return; } + tempBits &= ~8388608L; } - if (((_bits & 33554432L) != 0)) + if ((tempBits & 16777216L) != 0) { _headers._RetryAfter = default(StringValues); - _bits &= ~33554432L; - if(_bits == 0) + if((tempBits & ~16777216L) == 0) { return; } + tempBits &= ~16777216L; } - if (((_bits & 134217728L) != 0)) + if ((tempBits & 67108864L) != 0) { _headers._SetCookie = default(StringValues); - _bits &= ~134217728L; - if(_bits == 0) + if((tempBits & ~67108864L) == 0) { return; } + tempBits &= ~67108864L; } - if (((_bits & 268435456L) != 0)) + if ((tempBits & 134217728L) != 0) { _headers._Vary = default(StringValues); - _bits &= ~268435456L; - if(_bits == 0) + if((tempBits & ~134217728L) == 0) { return; } + tempBits &= ~134217728L; } - if (((_bits & 536870912L) != 0)) + if ((tempBits & 268435456L) != 0) { _headers._WWWAuthenticate = default(StringValues); - _bits &= ~536870912L; - if(_bits == 0) + if((tempBits & ~268435456L) == 0) { return; } + tempBits &= ~268435456L; } - if (((_bits & 1073741824L) != 0)) + if ((tempBits & 536870912L) != 0) { _headers._AccessControlAllowCredentials = default(StringValues); - _bits &= ~1073741824L; - if(_bits == 0) + if((tempBits & ~536870912L) == 0) { return; } + tempBits &= ~536870912L; } - if (((_bits & 2147483648L) != 0)) + if ((tempBits & 1073741824L) != 0) { _headers._AccessControlAllowHeaders = default(StringValues); - _bits &= ~2147483648L; - if(_bits == 0) + if((tempBits & ~1073741824L) == 0) { return; } + tempBits &= ~1073741824L; } - if (((_bits & 4294967296L) != 0)) + if ((tempBits & 2147483648L) != 0) { _headers._AccessControlAllowMethods = default(StringValues); - _bits &= ~4294967296L; - if(_bits == 0) + if((tempBits & ~2147483648L) == 0) { return; } + tempBits &= ~2147483648L; } - if (((_bits & 8589934592L) != 0)) + if ((tempBits & 4294967296L) != 0) { _headers._AccessControlAllowOrigin = default(StringValues); - _bits &= ~8589934592L; - if(_bits == 0) + if((tempBits & ~4294967296L) == 0) { return; } + tempBits &= ~4294967296L; } - if (((_bits & 17179869184L) != 0)) + if ((tempBits & 8589934592L) != 0) { _headers._AccessControlExposeHeaders = default(StringValues); - _bits &= ~17179869184L; - if(_bits == 0) + if((tempBits & ~8589934592L) == 0) { return; } + tempBits &= ~8589934592L; } - if (((_bits & 34359738368L) != 0)) + if ((tempBits & 17179869184L) != 0) { _headers._AccessControlMaxAge = default(StringValues); - _bits &= ~34359738368L; - if(_bits == 0) + if((tempBits & ~17179869184L) == 0) { return; } + tempBits &= ~17179869184L; } } - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override bool CopyToFast(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0) { - ThrowArgumentException(); + return false; } - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Cache-Control", _headers._CacheControl); ++arrayIndex; } - - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Connection", _headers._Connection); ++arrayIndex; } - - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Date", _headers._Date); ++arrayIndex; } - - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Keep-Alive", _headers._KeepAlive); ++arrayIndex; } - - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Pragma", _headers._Pragma); ++arrayIndex; } - - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Trailer", _headers._Trailer); ++arrayIndex; } - - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Transfer-Encoding", _headers._TransferEncoding); ++arrayIndex; } - - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Upgrade", _headers._Upgrade); ++arrayIndex; } - - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Via", _headers._Via); ++arrayIndex; } - - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Warning", _headers._Warning); ++arrayIndex; } - - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Allow", _headers._Allow); ++arrayIndex; } - - if (((_bits & 2048L) != 0)) - { - if (arrayIndex == array.Length) - { - ThrowArgumentException(); - } - - array[arrayIndex] = new KeyValuePair("Content-Length", _headers._ContentLength); - ++arrayIndex; - } - - if (((_bits & 4096L) != 0)) + if ((_bits & 2048L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Type", _headers._ContentType); ++arrayIndex; } - - if (((_bits & 8192L) != 0)) + if ((_bits & 4096L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Encoding", _headers._ContentEncoding); ++arrayIndex; } - - if (((_bits & 16384L) != 0)) + if ((_bits & 8192L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Language", _headers._ContentLanguage); ++arrayIndex; } - - if (((_bits & 32768L) != 0)) + if ((_bits & 16384L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Location", _headers._ContentLocation); ++arrayIndex; } - - if (((_bits & 65536L) != 0)) + if ((_bits & 32768L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-MD5", _headers._ContentMD5); ++arrayIndex; } - - if (((_bits & 131072L) != 0)) + if ((_bits & 65536L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Content-Range", _headers._ContentRange); ++arrayIndex; } - - if (((_bits & 262144L) != 0)) + if ((_bits & 131072L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Expires", _headers._Expires); ++arrayIndex; } - - if (((_bits & 524288L) != 0)) + if ((_bits & 262144L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Last-Modified", _headers._LastModified); ++arrayIndex; } - - if (((_bits & 1048576L) != 0)) + if ((_bits & 524288L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Accept-Ranges", _headers._AcceptRanges); ++arrayIndex; } - - if (((_bits & 2097152L) != 0)) + if ((_bits & 1048576L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Age", _headers._Age); ++arrayIndex; } - - if (((_bits & 4194304L) != 0)) + if ((_bits & 2097152L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("ETag", _headers._ETag); ++arrayIndex; } - - if (((_bits & 8388608L) != 0)) + if ((_bits & 4194304L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Location", _headers._Location); ++arrayIndex; } - - if (((_bits & 16777216L) != 0)) + if ((_bits & 8388608L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Proxy-Authenticate", _headers._ProxyAuthenticate); ++arrayIndex; } - - if (((_bits & 33554432L) != 0)) + if ((_bits & 16777216L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Retry-After", _headers._RetryAfter); ++arrayIndex; } - - if (((_bits & 67108864L) != 0)) + if ((_bits & 33554432L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Server", _headers._Server); ++arrayIndex; } - - if (((_bits & 134217728L) != 0)) + if ((_bits & 67108864L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Set-Cookie", _headers._SetCookie); ++arrayIndex; } - - if (((_bits & 268435456L) != 0)) + if ((_bits & 134217728L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Vary", _headers._Vary); ++arrayIndex; } - - if (((_bits & 536870912L) != 0)) + if ((_bits & 268435456L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("WWW-Authenticate", _headers._WWWAuthenticate); ++arrayIndex; } - - if (((_bits & 1073741824L) != 0)) + if ((_bits & 536870912L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Credentials", _headers._AccessControlAllowCredentials); ++arrayIndex; } - - if (((_bits & 2147483648L) != 0)) + if ((_bits & 1073741824L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Headers", _headers._AccessControlAllowHeaders); ++arrayIndex; } - - if (((_bits & 4294967296L) != 0)) + if ((_bits & 2147483648L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Methods", _headers._AccessControlAllowMethods); ++arrayIndex; } - - if (((_bits & 8589934592L) != 0)) + if ((_bits & 4294967296L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Allow-Origin", _headers._AccessControlAllowOrigin); ++arrayIndex; } - - if (((_bits & 17179869184L) != 0)) + if ((_bits & 8589934592L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Expose-Headers", _headers._AccessControlExposeHeaders); ++arrayIndex; } - - if (((_bits & 34359738368L) != 0)) + if ((_bits & 17179869184L) != 0) { if (arrayIndex == array.Length) { - ThrowArgumentException(); + return false; } - array[arrayIndex] = new KeyValuePair("Access-Control-Max-Age", _headers._AccessControlMaxAge); ++arrayIndex; } - + if (_contentLength.HasValue) + { + if (arrayIndex == array.Length) + { + return false; + } + array[arrayIndex] = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_contentLength.Value)); + ++arrayIndex; + } ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + + return true; } protected void CopyToFast(ref MemoryPoolIterator output) { - var tempBits = _bits; + var tempBits = _bits | (_contentLength.HasValue ? -9223372036854775808L : 0); - if (((_bits & 2L) != 0)) + if ((tempBits & 2L) != 0) { if (_headers._rawConnection != null) { @@ -9904,14 +7779,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~2L; - if(tempBits == 0) + if((tempBits & ~2L) == 0) { return; } + tempBits &= ~2L; } - - if (((_bits & 4L) != 0)) + if ((tempBits & 4L) != 0) { if (_headers._rawDate != null) { @@ -9931,41 +7805,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~4L; - if(tempBits == 0) - { - return; - } - } - - if (((_bits & 2048L) != 0)) - { - if (_headers._rawContentLength != null) - { - output.CopyFrom(_headers._rawContentLength, 0, _headers._rawContentLength.Length); - } - else - { - var valueCount = _headers._ContentLength.Count; - for (var i = 0; i < valueCount; i++) - { - var value = _headers._ContentLength[i]; - if (value != null) - { - output.CopyFrom(_headerBytes, 133, 18); - output.CopyFromAscii(value); - } - } - } - - tempBits &= ~2048L; - if(tempBits == 0) + if((tempBits & ~4L) == 0) { return; } + tempBits &= ~4L; } - - if (((_bits & 4096L) != 0)) + if ((tempBits & 2048L) != 0) { { var valueCount = _headers._ContentType.Count; @@ -9974,20 +7820,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ContentType[i]; if (value != null) { - output.CopyFrom(_headerBytes, 151, 16); + output.CopyFrom(_headerBytes, 133, 16); output.CopyFromAscii(value); } } } - tempBits &= ~4096L; - if(tempBits == 0) + if((tempBits & ~2048L) == 0) { return; } + tempBits &= ~2048L; } - - if (((_bits & 67108864L) != 0)) + if ((tempBits & 33554432L) != 0) { if (_headers._rawServer != null) { @@ -10001,20 +7846,30 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._Server[i]; if (value != null) { - output.CopyFrom(_headerBytes, 368, 10); + output.CopyFrom(_headerBytes, 350, 10); output.CopyFromAscii(value); } } } - tempBits &= ~67108864L; - if(tempBits == 0) + if((tempBits & ~33554432L) == 0) { return; } + tempBits &= ~33554432L; } - - if (((_bits & 1L) != 0)) + if ((tempBits & -9223372036854775808L) != 0) + { + output.CopyFrom(_headerBytes, 592, 18); + output.CopyFromNumeric((ulong)ContentLength.Value); + + if((tempBits & ~-9223372036854775808L) == 0) + { + return; + } + tempBits &= ~-9223372036854775808L; + } + if ((tempBits & 1L) != 0) { { var valueCount = _headers._CacheControl.Count; @@ -10029,14 +7884,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~1L; - if(tempBits == 0) + if((tempBits & ~1L) == 0) { return; } + tempBits &= ~1L; } - - if (((_bits & 8L) != 0)) + if ((tempBits & 8L) != 0) { { var valueCount = _headers._KeepAlive.Count; @@ -10051,14 +7905,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~8L; - if(tempBits == 0) + if((tempBits & ~8L) == 0) { return; } + tempBits &= ~8L; } - - if (((_bits & 16L) != 0)) + if ((tempBits & 16L) != 0) { { var valueCount = _headers._Pragma.Count; @@ -10073,14 +7926,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~16L; - if(tempBits == 0) + if((tempBits & ~16L) == 0) { return; } + tempBits &= ~16L; } - - if (((_bits & 32L) != 0)) + if ((tempBits & 32L) != 0) { { var valueCount = _headers._Trailer.Count; @@ -10095,14 +7947,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~32L; - if(tempBits == 0) + if((tempBits & ~32L) == 0) { return; } + tempBits &= ~32L; } - - if (((_bits & 64L) != 0)) + if ((tempBits & 64L) != 0) { if (_headers._rawTransferEncoding != null) { @@ -10122,14 +7973,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~64L; - if(tempBits == 0) + if((tempBits & ~64L) == 0) { return; } + tempBits &= ~64L; } - - if (((_bits & 128L) != 0)) + if ((tempBits & 128L) != 0) { { var valueCount = _headers._Upgrade.Count; @@ -10144,14 +7994,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~128L; - if(tempBits == 0) + if((tempBits & ~128L) == 0) { return; } + tempBits &= ~128L; } - - if (((_bits & 256L) != 0)) + if ((tempBits & 256L) != 0) { { var valueCount = _headers._Via.Count; @@ -10166,14 +8015,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~256L; - if(tempBits == 0) + if((tempBits & ~256L) == 0) { return; } + tempBits &= ~256L; } - - if (((_bits & 512L) != 0)) + if ((tempBits & 512L) != 0) { { var valueCount = _headers._Warning.Count; @@ -10188,14 +8036,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~512L; - if(tempBits == 0) + if((tempBits & ~512L) == 0) { return; } + tempBits &= ~512L; } - - if (((_bits & 1024L) != 0)) + if ((tempBits & 1024L) != 0) { { var valueCount = _headers._Allow.Count; @@ -10210,14 +8057,13 @@ protected void CopyToFast(ref MemoryPoolIterator output) } } - tempBits &= ~1024L; - if(tempBits == 0) + if((tempBits & ~1024L) == 0) { return; } + tempBits &= ~1024L; } - - if (((_bits & 8192L) != 0)) + if ((tempBits & 4096L) != 0) { { var valueCount = _headers._ContentEncoding.Count; @@ -10226,20 +8072,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ContentEncoding[i]; if (value != null) { - output.CopyFrom(_headerBytes, 167, 20); + output.CopyFrom(_headerBytes, 149, 20); output.CopyFromAscii(value); } } } - tempBits &= ~8192L; - if(tempBits == 0) + if((tempBits & ~4096L) == 0) { return; } + tempBits &= ~4096L; } - - if (((_bits & 16384L) != 0)) + if ((tempBits & 8192L) != 0) { { var valueCount = _headers._ContentLanguage.Count; @@ -10248,20 +8093,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ContentLanguage[i]; if (value != null) { - output.CopyFrom(_headerBytes, 187, 20); + output.CopyFrom(_headerBytes, 169, 20); output.CopyFromAscii(value); } } } - tempBits &= ~16384L; - if(tempBits == 0) + if((tempBits & ~8192L) == 0) { return; } + tempBits &= ~8192L; } - - if (((_bits & 32768L) != 0)) + if ((tempBits & 16384L) != 0) { { var valueCount = _headers._ContentLocation.Count; @@ -10270,20 +8114,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ContentLocation[i]; if (value != null) { - output.CopyFrom(_headerBytes, 207, 20); + output.CopyFrom(_headerBytes, 189, 20); output.CopyFromAscii(value); } } } - tempBits &= ~32768L; - if(tempBits == 0) + if((tempBits & ~16384L) == 0) { return; } + tempBits &= ~16384L; } - - if (((_bits & 65536L) != 0)) + if ((tempBits & 32768L) != 0) { { var valueCount = _headers._ContentMD5.Count; @@ -10292,20 +8135,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ContentMD5[i]; if (value != null) { - output.CopyFrom(_headerBytes, 227, 15); + output.CopyFrom(_headerBytes, 209, 15); output.CopyFromAscii(value); } } } - tempBits &= ~65536L; - if(tempBits == 0) + if((tempBits & ~32768L) == 0) { return; } + tempBits &= ~32768L; } - - if (((_bits & 131072L) != 0)) + if ((tempBits & 65536L) != 0) { { var valueCount = _headers._ContentRange.Count; @@ -10314,20 +8156,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ContentRange[i]; if (value != null) { - output.CopyFrom(_headerBytes, 242, 17); + output.CopyFrom(_headerBytes, 224, 17); output.CopyFromAscii(value); } } } - tempBits &= ~131072L; - if(tempBits == 0) + if((tempBits & ~65536L) == 0) { return; } + tempBits &= ~65536L; } - - if (((_bits & 262144L) != 0)) + if ((tempBits & 131072L) != 0) { { var valueCount = _headers._Expires.Count; @@ -10336,20 +8177,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._Expires[i]; if (value != null) { - output.CopyFrom(_headerBytes, 259, 11); + output.CopyFrom(_headerBytes, 241, 11); output.CopyFromAscii(value); } } } - tempBits &= ~262144L; - if(tempBits == 0) + if((tempBits & ~131072L) == 0) { return; } + tempBits &= ~131072L; } - - if (((_bits & 524288L) != 0)) + if ((tempBits & 262144L) != 0) { { var valueCount = _headers._LastModified.Count; @@ -10358,20 +8198,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._LastModified[i]; if (value != null) { - output.CopyFrom(_headerBytes, 270, 17); + output.CopyFrom(_headerBytes, 252, 17); output.CopyFromAscii(value); } } } - tempBits &= ~524288L; - if(tempBits == 0) + if((tempBits & ~262144L) == 0) { return; } + tempBits &= ~262144L; } - - if (((_bits & 1048576L) != 0)) + if ((tempBits & 524288L) != 0) { { var valueCount = _headers._AcceptRanges.Count; @@ -10380,20 +8219,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AcceptRanges[i]; if (value != null) { - output.CopyFrom(_headerBytes, 287, 17); + output.CopyFrom(_headerBytes, 269, 17); output.CopyFromAscii(value); } } } - tempBits &= ~1048576L; - if(tempBits == 0) + if((tempBits & ~524288L) == 0) { return; } + tempBits &= ~524288L; } - - if (((_bits & 2097152L) != 0)) + if ((tempBits & 1048576L) != 0) { { var valueCount = _headers._Age.Count; @@ -10402,20 +8240,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._Age[i]; if (value != null) { - output.CopyFrom(_headerBytes, 304, 7); + output.CopyFrom(_headerBytes, 286, 7); output.CopyFromAscii(value); } } } - tempBits &= ~2097152L; - if(tempBits == 0) + if((tempBits & ~1048576L) == 0) { return; } + tempBits &= ~1048576L; } - - if (((_bits & 4194304L) != 0)) + if ((tempBits & 2097152L) != 0) { { var valueCount = _headers._ETag.Count; @@ -10424,20 +8261,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ETag[i]; if (value != null) { - output.CopyFrom(_headerBytes, 311, 8); + output.CopyFrom(_headerBytes, 293, 8); output.CopyFromAscii(value); } } } - tempBits &= ~4194304L; - if(tempBits == 0) + if((tempBits & ~2097152L) == 0) { return; } + tempBits &= ~2097152L; } - - if (((_bits & 8388608L) != 0)) + if ((tempBits & 4194304L) != 0) { { var valueCount = _headers._Location.Count; @@ -10446,20 +8282,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._Location[i]; if (value != null) { - output.CopyFrom(_headerBytes, 319, 12); + output.CopyFrom(_headerBytes, 301, 12); output.CopyFromAscii(value); } } } - tempBits &= ~8388608L; - if(tempBits == 0) + if((tempBits & ~4194304L) == 0) { return; } + tempBits &= ~4194304L; } - - if (((_bits & 16777216L) != 0)) + if ((tempBits & 8388608L) != 0) { { var valueCount = _headers._ProxyAuthenticate.Count; @@ -10468,20 +8303,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._ProxyAuthenticate[i]; if (value != null) { - output.CopyFrom(_headerBytes, 331, 22); + output.CopyFrom(_headerBytes, 313, 22); output.CopyFromAscii(value); } } } - tempBits &= ~16777216L; - if(tempBits == 0) + if((tempBits & ~8388608L) == 0) { return; } + tempBits &= ~8388608L; } - - if (((_bits & 33554432L) != 0)) + if ((tempBits & 16777216L) != 0) { { var valueCount = _headers._RetryAfter.Count; @@ -10490,20 +8324,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._RetryAfter[i]; if (value != null) { - output.CopyFrom(_headerBytes, 353, 15); + output.CopyFrom(_headerBytes, 335, 15); output.CopyFromAscii(value); } } } - tempBits &= ~33554432L; - if(tempBits == 0) + if((tempBits & ~16777216L) == 0) { return; } + tempBits &= ~16777216L; } - - if (((_bits & 134217728L) != 0)) + if ((tempBits & 67108864L) != 0) { { var valueCount = _headers._SetCookie.Count; @@ -10512,20 +8345,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._SetCookie[i]; if (value != null) { - output.CopyFrom(_headerBytes, 378, 14); + output.CopyFrom(_headerBytes, 360, 14); output.CopyFromAscii(value); } } } - tempBits &= ~134217728L; - if(tempBits == 0) + if((tempBits & ~67108864L) == 0) { return; } + tempBits &= ~67108864L; } - - if (((_bits & 268435456L) != 0)) + if ((tempBits & 134217728L) != 0) { { var valueCount = _headers._Vary.Count; @@ -10534,20 +8366,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._Vary[i]; if (value != null) { - output.CopyFrom(_headerBytes, 392, 8); + output.CopyFrom(_headerBytes, 374, 8); output.CopyFromAscii(value); } } } - tempBits &= ~268435456L; - if(tempBits == 0) + if((tempBits & ~134217728L) == 0) { return; } + tempBits &= ~134217728L; } - - if (((_bits & 536870912L) != 0)) + if ((tempBits & 268435456L) != 0) { { var valueCount = _headers._WWWAuthenticate.Count; @@ -10556,20 +8387,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._WWWAuthenticate[i]; if (value != null) { - output.CopyFrom(_headerBytes, 400, 20); + output.CopyFrom(_headerBytes, 382, 20); output.CopyFromAscii(value); } } } - tempBits &= ~536870912L; - if(tempBits == 0) + if((tempBits & ~268435456L) == 0) { return; } + tempBits &= ~268435456L; } - - if (((_bits & 1073741824L) != 0)) + if ((tempBits & 536870912L) != 0) { { var valueCount = _headers._AccessControlAllowCredentials.Count; @@ -10578,20 +8408,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AccessControlAllowCredentials[i]; if (value != null) { - output.CopyFrom(_headerBytes, 420, 36); + output.CopyFrom(_headerBytes, 402, 36); output.CopyFromAscii(value); } } } - tempBits &= ~1073741824L; - if(tempBits == 0) + if((tempBits & ~536870912L) == 0) { return; } + tempBits &= ~536870912L; } - - if (((_bits & 2147483648L) != 0)) + if ((tempBits & 1073741824L) != 0) { { var valueCount = _headers._AccessControlAllowHeaders.Count; @@ -10600,20 +8429,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AccessControlAllowHeaders[i]; if (value != null) { - output.CopyFrom(_headerBytes, 456, 32); + output.CopyFrom(_headerBytes, 438, 32); output.CopyFromAscii(value); } } } - tempBits &= ~2147483648L; - if(tempBits == 0) + if((tempBits & ~1073741824L) == 0) { return; } + tempBits &= ~1073741824L; } - - if (((_bits & 4294967296L) != 0)) + if ((tempBits & 2147483648L) != 0) { { var valueCount = _headers._AccessControlAllowMethods.Count; @@ -10622,20 +8450,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AccessControlAllowMethods[i]; if (value != null) { - output.CopyFrom(_headerBytes, 488, 32); + output.CopyFrom(_headerBytes, 470, 32); output.CopyFromAscii(value); } } } - tempBits &= ~4294967296L; - if(tempBits == 0) + if((tempBits & ~2147483648L) == 0) { return; } + tempBits &= ~2147483648L; } - - if (((_bits & 8589934592L) != 0)) + if ((tempBits & 4294967296L) != 0) { { var valueCount = _headers._AccessControlAllowOrigin.Count; @@ -10644,20 +8471,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AccessControlAllowOrigin[i]; if (value != null) { - output.CopyFrom(_headerBytes, 520, 31); + output.CopyFrom(_headerBytes, 502, 31); output.CopyFromAscii(value); } } } - tempBits &= ~8589934592L; - if(tempBits == 0) + if((tempBits & ~4294967296L) == 0) { return; } + tempBits &= ~4294967296L; } - - if (((_bits & 17179869184L) != 0)) + if ((tempBits & 8589934592L) != 0) { { var valueCount = _headers._AccessControlExposeHeaders.Count; @@ -10666,20 +8492,19 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AccessControlExposeHeaders[i]; if (value != null) { - output.CopyFrom(_headerBytes, 551, 33); + output.CopyFrom(_headerBytes, 533, 33); output.CopyFromAscii(value); } } } - tempBits &= ~17179869184L; - if(tempBits == 0) + if((tempBits & ~8589934592L) == 0) { return; } + tempBits &= ~8589934592L; } - - if (((_bits & 34359738368L) != 0)) + if ((tempBits & 17179869184L) != 0) { { var valueCount = _headers._AccessControlMaxAge.Count; @@ -10688,23 +8513,21 @@ protected void CopyToFast(ref MemoryPoolIterator output) var value = _headers._AccessControlMaxAge[i]; if (value != null) { - output.CopyFrom(_headerBytes, 584, 26); + output.CopyFrom(_headerBytes, 566, 26); output.CopyFromAscii(value); } } } - tempBits &= ~34359738368L; - if(tempBits == 0) + if((tempBits & ~17179869184L) == 0) { return; } + tempBits &= ~17179869184L; } - } - - + private struct HeaderReferences { public StringValues _CacheControl; @@ -10718,7 +8541,6 @@ private struct HeaderReferences public StringValues _Via; public StringValues _Warning; public StringValues _Allow; - public StringValues _ContentLength; public StringValues _ContentType; public StringValues _ContentEncoding; public StringValues _ContentLanguage; @@ -10747,7 +8569,6 @@ private struct HeaderReferences public byte[] _rawConnection; public byte[] _rawDate; public byte[] _rawTransferEncoding; - public byte[] _rawContentLength; public byte[] _rawServer; } @@ -10758,120 +8579,119 @@ public bool MoveNext() switch (_state) { - case 0: - goto state0; - - case 1: - goto state1; + case 0: + goto state0; - case 2: - goto state2; + case 1: + goto state1; - case 3: - goto state3; + case 2: + goto state2; - case 4: - goto state4; + case 3: + goto state3; - case 5: - goto state5; + case 4: + goto state4; - case 6: - goto state6; + case 5: + goto state5; - case 7: - goto state7; + case 6: + goto state6; - case 8: - goto state8; + case 7: + goto state7; - case 9: - goto state9; + case 8: + goto state8; - case 10: - goto state10; + case 9: + goto state9; - case 11: - goto state11; + case 10: + goto state10; - case 12: - goto state12; + case 11: + goto state11; - case 13: - goto state13; + case 12: + goto state12; - case 14: - goto state14; + case 13: + goto state13; - case 15: - goto state15; + case 14: + goto state14; - case 16: - goto state16; + case 15: + goto state15; - case 17: - goto state17; + case 16: + goto state16; - case 18: - goto state18; + case 17: + goto state17; - case 19: - goto state19; + case 18: + goto state18; - case 20: - goto state20; + case 19: + goto state19; - case 21: - goto state21; + case 20: + goto state20; - case 22: - goto state22; + case 21: + goto state21; - case 23: - goto state23; + case 22: + goto state22; - case 24: - goto state24; + case 23: + goto state23; - case 25: - goto state25; + case 24: + goto state24; - case 26: - goto state26; + case 25: + goto state25; - case 27: - goto state27; + case 26: + goto state26; - case 28: - goto state28; + case 27: + goto state27; - case 29: - goto state29; + case 28: + goto state28; - case 30: - goto state30; + case 29: + goto state29; - case 31: - goto state31; + case 30: + goto state30; - case 32: - goto state32; + case 31: + goto state31; - case 33: - goto state33; + case 32: + goto state32; - case 34: - goto state34; + case 33: + goto state33; - case 35: - goto state35; + case 34: + goto state34; + case 36: + goto state36; default: goto state_default; } state0: - if (((_bits & 1L) != 0)) + if ((_bits & 1L) != 0) { _current = new KeyValuePair("Cache-Control", _collection._headers._CacheControl); _state = 1; @@ -10879,7 +8699,7 @@ public bool MoveNext() } state1: - if (((_bits & 2L) != 0)) + if ((_bits & 2L) != 0) { _current = new KeyValuePair("Connection", _collection._headers._Connection); _state = 2; @@ -10887,7 +8707,7 @@ public bool MoveNext() } state2: - if (((_bits & 4L) != 0)) + if ((_bits & 4L) != 0) { _current = new KeyValuePair("Date", _collection._headers._Date); _state = 3; @@ -10895,7 +8715,7 @@ public bool MoveNext() } state3: - if (((_bits & 8L) != 0)) + if ((_bits & 8L) != 0) { _current = new KeyValuePair("Keep-Alive", _collection._headers._KeepAlive); _state = 4; @@ -10903,7 +8723,7 @@ public bool MoveNext() } state4: - if (((_bits & 16L) != 0)) + if ((_bits & 16L) != 0) { _current = new KeyValuePair("Pragma", _collection._headers._Pragma); _state = 5; @@ -10911,7 +8731,7 @@ public bool MoveNext() } state5: - if (((_bits & 32L) != 0)) + if ((_bits & 32L) != 0) { _current = new KeyValuePair("Trailer", _collection._headers._Trailer); _state = 6; @@ -10919,7 +8739,7 @@ public bool MoveNext() } state6: - if (((_bits & 64L) != 0)) + if ((_bits & 64L) != 0) { _current = new KeyValuePair("Transfer-Encoding", _collection._headers._TransferEncoding); _state = 7; @@ -10927,7 +8747,7 @@ public bool MoveNext() } state7: - if (((_bits & 128L) != 0)) + if ((_bits & 128L) != 0) { _current = new KeyValuePair("Upgrade", _collection._headers._Upgrade); _state = 8; @@ -10935,7 +8755,7 @@ public bool MoveNext() } state8: - if (((_bits & 256L) != 0)) + if ((_bits & 256L) != 0) { _current = new KeyValuePair("Via", _collection._headers._Via); _state = 9; @@ -10943,7 +8763,7 @@ public bool MoveNext() } state9: - if (((_bits & 512L) != 0)) + if ((_bits & 512L) != 0) { _current = new KeyValuePair("Warning", _collection._headers._Warning); _state = 10; @@ -10951,7 +8771,7 @@ public bool MoveNext() } state10: - if (((_bits & 1024L) != 0)) + if ((_bits & 1024L) != 0) { _current = new KeyValuePair("Allow", _collection._headers._Allow); _state = 11; @@ -10959,205 +8779,204 @@ public bool MoveNext() } state11: - if (((_bits & 2048L) != 0)) + if ((_bits & 2048L) != 0) { - _current = new KeyValuePair("Content-Length", _collection._headers._ContentLength); + _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); _state = 12; return true; } state12: - if (((_bits & 4096L) != 0)) + if ((_bits & 4096L) != 0) { - _current = new KeyValuePair("Content-Type", _collection._headers._ContentType); + _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); _state = 13; return true; } state13: - if (((_bits & 8192L) != 0)) + if ((_bits & 8192L) != 0) { - _current = new KeyValuePair("Content-Encoding", _collection._headers._ContentEncoding); + _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); _state = 14; return true; } state14: - if (((_bits & 16384L) != 0)) + if ((_bits & 16384L) != 0) { - _current = new KeyValuePair("Content-Language", _collection._headers._ContentLanguage); + _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); _state = 15; return true; } state15: - if (((_bits & 32768L) != 0)) + if ((_bits & 32768L) != 0) { - _current = new KeyValuePair("Content-Location", _collection._headers._ContentLocation); + _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); _state = 16; return true; } state16: - if (((_bits & 65536L) != 0)) + if ((_bits & 65536L) != 0) { - _current = new KeyValuePair("Content-MD5", _collection._headers._ContentMD5); + _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); _state = 17; return true; } state17: - if (((_bits & 131072L) != 0)) + if ((_bits & 131072L) != 0) { - _current = new KeyValuePair("Content-Range", _collection._headers._ContentRange); + _current = new KeyValuePair("Expires", _collection._headers._Expires); _state = 18; return true; } state18: - if (((_bits & 262144L) != 0)) + if ((_bits & 262144L) != 0) { - _current = new KeyValuePair("Expires", _collection._headers._Expires); + _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); _state = 19; return true; } state19: - if (((_bits & 524288L) != 0)) + if ((_bits & 524288L) != 0) { - _current = new KeyValuePair("Last-Modified", _collection._headers._LastModified); + _current = new KeyValuePair("Accept-Ranges", _collection._headers._AcceptRanges); _state = 20; return true; } state20: - if (((_bits & 1048576L) != 0)) + if ((_bits & 1048576L) != 0) { - _current = new KeyValuePair("Accept-Ranges", _collection._headers._AcceptRanges); + _current = new KeyValuePair("Age", _collection._headers._Age); _state = 21; return true; } state21: - if (((_bits & 2097152L) != 0)) + if ((_bits & 2097152L) != 0) { - _current = new KeyValuePair("Age", _collection._headers._Age); + _current = new KeyValuePair("ETag", _collection._headers._ETag); _state = 22; return true; } state22: - if (((_bits & 4194304L) != 0)) + if ((_bits & 4194304L) != 0) { - _current = new KeyValuePair("ETag", _collection._headers._ETag); + _current = new KeyValuePair("Location", _collection._headers._Location); _state = 23; return true; } state23: - if (((_bits & 8388608L) != 0)) + if ((_bits & 8388608L) != 0) { - _current = new KeyValuePair("Location", _collection._headers._Location); + _current = new KeyValuePair("Proxy-Authenticate", _collection._headers._ProxyAuthenticate); _state = 24; return true; } state24: - if (((_bits & 16777216L) != 0)) + if ((_bits & 16777216L) != 0) { - _current = new KeyValuePair("Proxy-Authenticate", _collection._headers._ProxyAuthenticate); + _current = new KeyValuePair("Retry-After", _collection._headers._RetryAfter); _state = 25; return true; } state25: - if (((_bits & 33554432L) != 0)) + if ((_bits & 33554432L) != 0) { - _current = new KeyValuePair("Retry-After", _collection._headers._RetryAfter); + _current = new KeyValuePair("Server", _collection._headers._Server); _state = 26; return true; } state26: - if (((_bits & 67108864L) != 0)) + if ((_bits & 67108864L) != 0) { - _current = new KeyValuePair("Server", _collection._headers._Server); + _current = new KeyValuePair("Set-Cookie", _collection._headers._SetCookie); _state = 27; return true; } state27: - if (((_bits & 134217728L) != 0)) + if ((_bits & 134217728L) != 0) { - _current = new KeyValuePair("Set-Cookie", _collection._headers._SetCookie); + _current = new KeyValuePair("Vary", _collection._headers._Vary); _state = 28; return true; } state28: - if (((_bits & 268435456L) != 0)) + if ((_bits & 268435456L) != 0) { - _current = new KeyValuePair("Vary", _collection._headers._Vary); + _current = new KeyValuePair("WWW-Authenticate", _collection._headers._WWWAuthenticate); _state = 29; return true; } state29: - if (((_bits & 536870912L) != 0)) + if ((_bits & 536870912L) != 0) { - _current = new KeyValuePair("WWW-Authenticate", _collection._headers._WWWAuthenticate); + _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._headers._AccessControlAllowCredentials); _state = 30; return true; } state30: - if (((_bits & 1073741824L) != 0)) + if ((_bits & 1073741824L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Credentials", _collection._headers._AccessControlAllowCredentials); + _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._headers._AccessControlAllowHeaders); _state = 31; return true; } state31: - if (((_bits & 2147483648L) != 0)) + if ((_bits & 2147483648L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Headers", _collection._headers._AccessControlAllowHeaders); + _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._headers._AccessControlAllowMethods); _state = 32; return true; } state32: - if (((_bits & 4294967296L) != 0)) + if ((_bits & 4294967296L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Methods", _collection._headers._AccessControlAllowMethods); + _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._headers._AccessControlAllowOrigin); _state = 33; return true; } state33: - if (((_bits & 8589934592L) != 0)) + if ((_bits & 8589934592L) != 0) { - _current = new KeyValuePair("Access-Control-Allow-Origin", _collection._headers._AccessControlAllowOrigin); + _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._headers._AccessControlExposeHeaders); _state = 34; return true; } state34: - if (((_bits & 17179869184L) != 0)) + if ((_bits & 17179869184L) != 0) { - _current = new KeyValuePair("Access-Control-Expose-Headers", _collection._headers._AccessControlExposeHeaders); + _current = new KeyValuePair("Access-Control-Max-Age", _collection._headers._AccessControlMaxAge); _state = 35; return true; } - state35: - if (((_bits & 34359738368L) != 0)) + state36: + if (_collection._contentLength.HasValue) { - _current = new KeyValuePair("Access-Control-Max-Age", _collection._headers._AccessControlMaxAge); - _state = 36; + _current = new KeyValuePair("Content-Length", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _state = 37; return true; } - state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs index 4cb77a278..312fc0dfd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs @@ -5,19 +5,32 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract class FrameHeaders : IHeaderDictionary { + protected long? _contentLength; protected bool _isReadOnly; protected Dictionary MaybeUnknown; - protected Dictionary Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary(StringComparer.OrdinalIgnoreCase)); + public long? ContentLength + { + get { return _contentLength; } + set + { + if (value.HasValue && value.Value < 0) + { + ThrowInvalidContentLengthException(value.Value); + } + _contentLength = value; + } + } + StringValues IHeaderDictionary.this[string key] { get @@ -41,7 +54,12 @@ StringValues IDictionary.this[string key] get { // Unlike the IHeaderDictionary version, this getter will throw a KeyNotFoundException. - return GetValueFast(key); + StringValues value; + if (!TryGetValueFast(key, out value)) + { + ThrowKeyNotFoundException(); + } + return value; } set { @@ -88,6 +106,7 @@ public void Reset() ClearFast(); } + [MethodImpl(MethodImplOptions.NoInlining)] protected static StringValues AppendValue(StringValues existing, string append) { return StringValues.Concat(existing, append); @@ -112,16 +131,13 @@ protected static int BitCount(long value) protected virtual int GetCountFast() { throw new NotImplementedException(); } - protected virtual StringValues GetValueFast(string key) - { throw new NotImplementedException(); } - protected virtual bool TryGetValueFast(string key, out StringValues value) { throw new NotImplementedException(); } protected virtual void SetValueFast(string key, StringValues value) { throw new NotImplementedException(); } - protected virtual void AddValueFast(string key, StringValues value) + protected virtual bool AddValueFast(string key, StringValues value) { throw new NotImplementedException(); } protected virtual bool RemoveFast(string key) @@ -130,7 +146,7 @@ protected virtual bool RemoveFast(string key) protected virtual void ClearFast() { throw new NotImplementedException(); } - protected virtual void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected virtual bool CopyToFast(KeyValuePair[] array, int arrayIndex) { throw new NotImplementedException(); } protected virtual IEnumerator> GetEnumeratorFast() @@ -147,7 +163,11 @@ void IDictionary.Add(string key, StringValues value) { ThrowHeadersReadOnlyException(); } - AddValueFast(key, value); + + if (!AddValueFast(key, value)) + { + ThrowDuplicateKeyException(); + } } void ICollection>.Clear() @@ -175,7 +195,10 @@ bool IDictionary.ContainsKey(string key) void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { - CopyToFast(array, arrayIndex); + if (!CopyToFast(array, arrayIndex)) + { + ThrowArgumentException(); + } } IEnumerator IEnumerable.GetEnumerator() @@ -235,17 +258,6 @@ public static void ValidateHeaderCharacters(string headerCharacters) } } - public static long ParseContentLength(StringValues value) - { - long parsed; - if (!HeaderUtilities.TryParseInt64(value.ToString(), out parsed)) - { - ThrowInvalidContentLengthException(value); - } - - return parsed; - } - public static unsafe ConnectionOptions ParseConnection(StringValues connection) { var connectionOptions = ConnectionOptions.None; @@ -412,9 +424,9 @@ public static unsafe TransferCoding GetFinalTransferCoding(StringValues transfer return transferEncodingOptions; } - private static void ThrowInvalidContentLengthException(string value) + private static void ThrowInvalidContentLengthException(long value) { - throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); + throw new ArgumentOutOfRangeException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); } private static void ThrowInvalidHeaderCharacter(char ch) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs index 7d24bf3d8..4dd46d5cf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameRequestHeaders.cs @@ -3,12 +3,59 @@ using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public partial class FrameRequestHeaders : FrameHeaders { + private static long ParseContentLength(string value) + { + long parsed; + if (!HeaderUtilities.TryParseInt64(value, out parsed)) + { + ThrowInvalidContentLengthException(value); + } + + return parsed; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void SetValueUnknown(string key, StringValues value) + { + Unknown[key] = value; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private unsafe void AppendUnknownHeaders(byte* pKeyBytes, int keyLength, string value) + { + string key = new string('\0', keyLength); + fixed (char* keyBuffer = key) + { + if (!AsciiUtilities.TryGetAsciiString(pKeyBytes, keyBuffer, keyLength)) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); + } + } + + StringValues existing; + Unknown.TryGetValue(key, out existing); + Unknown[key] = AppendValue(existing, value); + } + + private static void ThrowInvalidContentLengthException(string value) + { + throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidContentLength, value); + } + + private static void ThrowMultipleContentLengthsException() + { + throw BadHttpRequestException.GetException(RequestRejectionReason.MultipleContentLengths); + } + public Enumerator GetEnumerator() { return new Enumerator(this); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs index ccb5e0d46..4666041dd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameResponseHeaders.cs @@ -1,10 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { @@ -13,20 +16,14 @@ public partial class FrameResponseHeaders : FrameHeaders private static readonly byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; private static readonly byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; - private long? _contentLength; - public bool HasConnection => HeaderConnection.Count != 0; public bool HasTransferEncoding => HeaderTransferEncoding.Count != 0; - public bool HasContentLength => HeaderContentLength.Count != 0; - public bool HasServer => HeaderServer.Count != 0; public bool HasDate => HeaderDate.Count != 0; - public long? HeaderContentLengthValue => _contentLength; - public Enumerator GetEnumerator() { return new Enumerator(this); @@ -58,6 +55,29 @@ public void CopyTo(ref MemoryPoolIterator output) } } + private static long ParseContentLength(string value) + { + long parsed; + if (!HeaderUtilities.TryParseInt64(value, out parsed)) + { + ThrowInvalidContentLengthException(value); + } + + return parsed; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void SetValueUnknown(string key, StringValues value) + { + ValidateHeaderCharacters(key); + Unknown[key] = value; + } + + private static void ThrowInvalidContentLengthException(string value) + { + throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number."); + } + public partial struct Enumerator : IEnumerator> { private readonly FrameResponseHeaders _collection; @@ -92,5 +112,6 @@ public void Reset() _state = 0; } } + } } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs index 50cb46874..99b10d1b4 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/MessageBody.cs @@ -8,12 +8,14 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http { public abstract class MessageBody { + private static readonly MessageBody _zeroContentLengthClose = new ForZeroContentLength(keepAlive: false); + private static readonly MessageBody _zeroContentLengthKeepAlive = new ForZeroContentLength(keepAlive: true); + private readonly Frame _context; private bool _send100Continue = true; @@ -266,18 +268,15 @@ public static MessageBody For( return new ForChunkedEncoding(keepAlive, headers, context); } - var unparsedContentLength = headers.HeaderContentLength; - if (unparsedContentLength.Count > 0) + if (headers.ContentLength.HasValue) { - try - { - var contentLength = FrameHeaders.ParseContentLength(unparsedContentLength); - return new ForContentLength(keepAlive, contentLength, context); - } - catch (InvalidOperationException) + var contentLength = headers.ContentLength.Value; + if (contentLength == 0) { - context.RejectRequest(RequestRejectionReason.InvalidContentLength, unparsedContentLength); + return keepAlive ? _zeroContentLengthKeepAlive : _zeroContentLengthClose; } + + return new ForContentLength(keepAlive, contentLength, context); } // Avoid slowing down most common case @@ -292,7 +291,7 @@ public static MessageBody For( } } - return new ForContentLength(keepAlive, 0, context); + return keepAlive ? _zeroContentLengthKeepAlive : _zeroContentLengthClose; } private class ForRemainingData : MessageBody @@ -309,6 +308,28 @@ protected override ValueTask> PeekAsync(CancellationToken can } } + private class ForZeroContentLength : MessageBody + { + public ForZeroContentLength(bool keepAlive) + : base(null) + { + RequestKeepAlive = keepAlive; + } + + protected override ValueTask> PeekAsync(CancellationToken cancellationToken) + { + return new ValueTask>(); + } + + protected override void OnConsumedBytes(int count) + { + if (count > 0) + { + throw new InvalidDataException("Consuming non-existent data"); + } + } + } + private class ForContentLength : MessageBody { private readonly long _contentLength; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs index 0c05a6b8e..caa6475d9 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs @@ -15,6 +15,7 @@ public enum RequestRejectionReason InvalidRequestLine, MalformedRequestInvalidHeaders, InvalidContentLength, + MultipleContentLengths, UnexpectedEndOfRequestContent, BadChunkSuffix, BadChunkSizeData, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs index b1b45eb6e..07491b737 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/MemoryPoolIterator.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure { public struct MemoryPoolIterator { + private const int _maxULongByteLength = 20; private const ulong _xorPowerOfTwoToHighByte = (0x07ul | 0x06ul << 8 | 0x05ul << 16 | @@ -23,6 +24,9 @@ public struct MemoryPoolIterator private static readonly int _vectorSpan = Vector.Count; + [ThreadStatic] + private static byte[] _numericBytesScratch; + private MemoryPoolBlock _block; private int _index; @@ -1082,6 +1086,101 @@ public unsafe void CopyFromAscii(string data) _index = blockIndex; } + private static byte[] NumericBytesScratch => _numericBytesScratch ?? CreateNumericBytesScratch(); + + [MethodImpl(MethodImplOptions.NoInlining)] + private static byte[] CreateNumericBytesScratch() + { + var bytes = new byte[_maxULongByteLength]; + _numericBytesScratch = bytes; + return bytes; + } + + public unsafe void CopyFromNumeric(ulong value) + { + const byte AsciiDigitStart = (byte)'0'; + + var block = _block; + if (block == null) + { + return; + } + + var blockIndex = _index; + var bytesLeftInBlock = block.Data.Offset + block.Data.Count - blockIndex; + var start = block.DataFixedPtr + blockIndex; + + if (value < 10) + { + if (bytesLeftInBlock < 1) + { + CopyFromNumericOverflow(value); + return; + } + _index = blockIndex + 1; + block.End = blockIndex + 1; + + *(start) = (byte)(((uint)value) + AsciiDigitStart); + } + else if (value < 100) + { + if (bytesLeftInBlock < 2) + { + CopyFromNumericOverflow(value); + return; + } + _index = blockIndex + 2; + block.End = blockIndex + 2; + + var val = (uint)value; + var tens = (byte)((val * 205u) >> 11); // div10, valid to 1028 + + *(start) = (byte)(tens + AsciiDigitStart); + *(start + 1) = (byte)(val - (tens * 10) + AsciiDigitStart); + } + else if (value < 1000) + { + if (bytesLeftInBlock < 3) + { + CopyFromNumericOverflow(value); + return; + } + _index = blockIndex + 3; + block.End = blockIndex + 3; + + var val = (uint)value; + var digit0 = (byte)((val * 41u) >> 12); // div100, valid to 1098 + var digits01 = (byte)((val * 205u) >> 11); // div10, valid to 1028 + + *(start) = (byte)(digit0 + AsciiDigitStart); + *(start + 1) = (byte)(digits01 - (digit0 * 10) + AsciiDigitStart); + *(start + 2) = (byte)(val - (digits01 * 10) + AsciiDigitStart); + } + else + { + CopyFromNumericOverflow(value); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private unsafe void CopyFromNumericOverflow(ulong value) + { + const byte AsciiDigitStart = (byte)'0'; + + var position = _maxULongByteLength; + var byteBuffer = NumericBytesScratch; + do + { + // Consider using Math.DivRem() if available + var quotient = value / 10; + byteBuffer[--position] = (byte)(AsciiDigitStart + (value - quotient * 10)); // 0x30 = '0' + value = quotient; + } + while (value != 0); + + CopyFrom(byteBuffer, position, _maxULongByteLength - position); + } + public unsafe string GetAsciiString(ref MemoryPoolIterator end) { var block = _block; @@ -1253,6 +1352,5 @@ public static Vector GetVector(byte vectorByte) // https://github.com/dotnet/coreclr/issues/7459#issuecomment-253965670 return Vector.AsVectorByte(new Vector(vectorByte * 0x01010101u)); } - } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs new file mode 100644 index 000000000..a8dcf7946 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs @@ -0,0 +1,209 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Internal; +using System.Runtime.CompilerServices; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + [Config(typeof(CoreConfig))] + public class ResponseHeaders + { + private const int InnerLoopCount = 512; + + private static readonly byte[] _bytesServer = Encoding.ASCII.GetBytes("\r\nServer: Kestrel"); + private static readonly DateHeaderValueManager _dateHeaderValueManager = new DateHeaderValueManager(); + private static readonly MemoryPool _memoryPool = new MemoryPool(); + private FrameResponseHeaders _responseHeadersDirect; + private HttpResponse _response; + + [Params("ContentLengthNumeric", "ContentLengthString", "Plaintext", "Common", "Unknown")] + public string Type { get; set; } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void SetHeaders() + { + switch (Type) + { + case "ContentLengthNumeric": + ContentLengthNumeric(InnerLoopCount); + break; + case "ContentLengthString": + ContentLengthString(InnerLoopCount); + break; + case "Plaintext": + Plaintext(InnerLoopCount); + break; + case "Common": + Common(InnerLoopCount); + break; + case "Unknown": + Unknown(InnerLoopCount); + break; + } + } + + [Benchmark(OperationsPerInvoke = InnerLoopCount)] + public void OutputHeaders() + { + for (var i = 0; i < InnerLoopCount; i++) + { + var block = _memoryPool.Lease(); + var iter = new MemoryPoolIterator(block); + _responseHeadersDirect.CopyTo(ref iter); + + ReturnBlocks(block); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void ContentLengthNumeric(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.ContentLength = 0; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void ContentLengthString(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.Headers["Content-Length"] = "0"; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void Plaintext(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.StatusCode = 200; + _response.ContentType = "text/plain"; + _response.ContentLength = 13; + + var dateHeaderValues = _dateHeaderValueManager.GetDateHeaderValues(); + _responseHeadersDirect.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + _responseHeadersDirect.SetRawServer("Kestrel", _bytesServer); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void Common(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.StatusCode = 200; + _response.ContentType = "text/css"; + _response.ContentLength = 421; + + var headers = _response.Headers; + + headers["Connection"] = "Close"; + headers["Cache-Control"] = "public, max-age=30672000"; + headers["Vary"] = "Accept-Encoding"; + headers["Content-Encoding"] = "gzip"; + headers["Expires"] = "Fri, 12 Jan 2018 22:01:55 GMT"; + headers["Last-Modified"] = "Wed, 22 Jun 2016 20:08:29 GMT"; + headers["Set-Cookie"] = "prov=20629ccd-8b0f-e8ef-2935-cd26609fc0bc; __qca=P0-1591065732-1479167353442; _ga=GA1.2.1298898376.1479167354; _gat=1; sgt=id=9519gfde_3347_4762_8762_df51458c8ec2; acct=t=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric&s=why-is-%e0%a5%a7%e0%a5%a8%e0%a5%a9-numeric"; + headers["ETag"] = "\"54ef7954-1078\""; + headers["Transfer-Encoding"] = "chunked"; + headers["Content-Language"] = "en-gb"; + headers["Upgrade"] = "websocket"; + headers["Via"] = "1.1 varnish"; + headers["Access-Control-Allow-Origin"] = "*"; + headers["Access-Control-Allow-credentials"] = "true"; + headers["Access-Control-Expose-Headers"] = "Client-Protocol, Content-Length, Content-Type, X-Bandwidth-Est, X-Bandwidth-Est2, X-Bandwidth-Est-Comp, X-Bandwidth-Avg, X-Walltime-Ms, X-Sequence-Num"; + + var dateHeaderValues = _dateHeaderValueManager.GetDateHeaderValues(); + _responseHeadersDirect.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + _responseHeadersDirect.SetRawServer("Kestrel", _bytesServer); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void Unknown(int count) + { + for (var i = 0; i < count; i++) + { + _responseHeadersDirect.Reset(); + + _response.StatusCode = 200; + _response.ContentType = "text/plain"; + _response.ContentLength = 13; + + var headers = _response.Headers; + + headers["Link"] = "; rel=\"canonical\""; + headers["X-Ua-Compatible"] = "IE=Edge"; + headers["X-Powered-By"] = "ASP.NET"; + headers["X-Content-Type-Options"] = "nosniff"; + headers["X-Xss-Protection"] = "1; mode=block"; + headers["X-Frame-Options"] = "SAMEORIGIN"; + headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains; preload"; + headers["Content-Security-Policy"] = "default-src 'none'; script-src 'self' cdnjs.cloudflare.com code.jquery.com scotthelme.disqus.com a.disquscdn.com www.google-analytics.com go.disqus.com platform.twitter.com cdn.syndication.twimg.com; style-src 'self' a.disquscdn.com fonts.googleapis.com cdnjs.cloudflare.com platform.twitter.com; img-src 'self' data: www.gravatar.com www.google-analytics.com links.services.disqus.com referrer.disqus.com a.disquscdn.com cdn.syndication.twimg.com syndication.twitter.com pbs.twimg.com platform.twitter.com abs.twimg.com; child-src fusiontables.googleusercontent.com fusiontables.google.com www.google.com disqus.com www.youtube.com syndication.twitter.com platform.twitter.com; frame-src fusiontables.googleusercontent.com fusiontables.google.com www.google.com disqus.com www.youtube.com syndication.twitter.com platform.twitter.com; connect-src 'self' links.services.disqus.com; font-src 'self' cdnjs.cloudflare.com fonts.gstatic.com fonts.googleapis.com; form-action 'self'; upgrade-insecure-requests;"; + + var dateHeaderValues = _dateHeaderValueManager.GetDateHeaderValues(); + _responseHeadersDirect.SetRawDate(dateHeaderValues.String, dateHeaderValues.Bytes); + _responseHeadersDirect.SetRawServer("Kestrel", _bytesServer); + } + } + + [Setup] + public void Setup() + { + var connectionContext = new MockConnection(new KestrelServerOptions()); + var frame = new Frame(application: null, context: connectionContext); + frame.Reset(); + frame.InitializeHeaders(); + _responseHeadersDirect = (FrameResponseHeaders)frame.ResponseHeaders; + var context = new DefaultHttpContext(frame); + _response = new DefaultHttpResponse(context); + + switch (Type) + { + case "ContentLengthNumeric": + ContentLengthNumeric(1); + break; + case "ContentLengthString": + ContentLengthString(1); + break; + case "Plaintext": + Plaintext(1); + break; + case "Common": + Common(1); + break; + case "Unknown": + Unknown(1); + break; + } + } + + private static void ReturnBlocks(MemoryPoolBlock block) + { + while (block != null) + { + var returningBlock = block; + block = returningBlock.Next; + + returningBlock.Pool.Return(returningBlock); + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs index 12e9969ed..9727e7110 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs @@ -15,7 +15,7 @@ public class RpsColumn : IColumn public string GetValue(Summary summary, Benchmark benchmark) { - var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark).ResultStatistics.Mean; + var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark)?.ResultStatistics?.Mean ?? 0; // Make sure we don't divide by zero!! return Math.Abs(totalNanos) > 0.0 ? (NanosPerSecond / totalNanos).ToString("N2") : "N/A"; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs index b211578da..ab681e546 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/BadHttpRequestTests.cs @@ -202,6 +202,21 @@ public async Task BadRequestIfMethodRequiresLengthButNoContentLengthInHttp10Requ } } + [Theory] + [InlineData("NaN")] + [InlineData("-1")] + public async Task BadRequestIfContentLengthInvalid(string contentLength) + { + using (var server = new TestServer(context => { return Task.FromResult(0); })) + { + using (var connection = server.CreateConnection()) + { + await connection.Send($"GET / HTTP/1.1\r\nContent-Length: {contentLength}\r\n\r\n"); + await ReceiveBadRequestResponse(connection, "400 Bad Request", server.Context.DateHeaderValue); + } + } + } + private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedResponseStatusCode, string expectedDateHeaderValue) { await connection.ReceiveForcedEnd( diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs index b8a843f73..2493387b9 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/DefaultHeaderTests.cs @@ -32,14 +32,14 @@ await connection.Send( await connection.ReceiveEnd( "HTTP/1.1 200 OK", $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", "Server: Kestrel", + "Content-Length: 0", "", "HTTP/1.1 200 OK", "Connection: close", $"Date: {testContext.DateHeaderValue}", - "Content-Length: 0", "Server: Kestrel", + "Content-Length: 0", "", ""); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs index 6e41b778e..83856879a 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameHeadersTests.cs @@ -1,8 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; using Xunit; namespace Microsoft.AspNetCore.Server.KestrelTests @@ -223,5 +226,65 @@ public void TestParseTransferEncodingMultipleValues(string value1, string value2 var transferEncodingOptions = FrameHeaders.GetFinalTransferCoding(transferEncoding); Assert.Equal(expectedTransferEncodingOptions, transferEncodingOptions); } + + [Fact] + public void ValidContentLengthsAccepted() + { + ValidContentLengthsAccepted(new FrameRequestHeaders()); + ValidContentLengthsAccepted(new FrameResponseHeaders()); + } + + private static void ValidContentLengthsAccepted(FrameHeaders frameHeaders) + { + IDictionary headers = frameHeaders; + + StringValues value; + + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + + frameHeaders.ContentLength = 1; + Assert.True(headers.TryGetValue("Content-Length", out value)); + Assert.Equal("1", value[0]); + Assert.Equal(1, frameHeaders.ContentLength); + Assert.True(frameHeaders.ContentLength.HasValue); + + frameHeaders.ContentLength = long.MaxValue; + Assert.True(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(HeaderUtilities.FormatInt64(long.MaxValue), value[0]); + Assert.Equal(long.MaxValue, frameHeaders.ContentLength); + Assert.True(frameHeaders.ContentLength.HasValue); + + frameHeaders.ContentLength = null; + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + } + + [Fact] + public void InvalidContentLengthsRejected() + { + InvalidContentLengthsRejected(new FrameRequestHeaders()); + InvalidContentLengthsRejected(new FrameResponseHeaders()); + } + + private static void InvalidContentLengthsRejected(FrameHeaders frameHeaders) + { + IDictionary headers = frameHeaders; + + StringValues value; + + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + + Assert.Throws(() => frameHeaders.ContentLength = -1); + Assert.Throws(() => frameHeaders.ContentLength = long.MinValue); + + Assert.False(headers.TryGetValue("Content-Length", out value)); + Assert.Equal(null, frameHeaders.ContentLength); + Assert.False(frameHeaders.ContentLength.HasValue); + } } } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs index b19ca0712..91212d627 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameRequestHeadersTests.cs @@ -41,10 +41,14 @@ public void SettingKnownHeadersWorks() IDictionary headers = new FrameRequestHeaders(); headers["host"] = new[] { "value" }; + headers["content-length"] = new[] { "0" }; Assert.NotNull(headers["host"]); + Assert.NotNull(headers["content-length"]); Assert.Equal(1, headers["host"].Count); + Assert.Equal(1, headers["content-length"].Count); Assert.Equal("value", headers["host"][0]); + Assert.Equal("0", headers["content-length"][0]); } [Fact] @@ -54,8 +58,9 @@ public void KnownAndCustomHeaderCountAddedTogether() headers["host"] = new[] { "value" }; headers["custom"] = new[] { "value" }; + headers["Content-Length"] = new[] { "0" }; - Assert.Equal(2, headers.Count); + Assert.Equal(3, headers.Count); } [Fact] @@ -66,14 +71,22 @@ public void TryGetValueWorksForKnownAndUnknownHeaders() StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); headers["host"] = new[] { "value" }; Assert.True(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); headers["custom"] = new[] { "value" }; Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); + + headers["Content-Length"] = new[] { "0" }; + Assert.True(headers.TryGetValue("host", out value)); + Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -83,6 +96,7 @@ public void SameExceptionThrownForMissingKey() Assert.Throws(() => headers["custom"]); Assert.Throws(() => headers["host"]); + Assert.Throws(() => headers["Content-Length"]); } [Fact] @@ -90,14 +104,17 @@ public void EntriesCanBeEnumerated() { IDictionary headers = new FrameRequestHeaders(); var v1 = new[] { "localhost" }; - var v2 = new[] { "value" }; + var v2 = new[] { "0" }; + var v3 = new[] { "value" }; headers["host"] = v1; - headers["custom"] = v2; + headers["Content-Length"] = v2; + headers["custom"] = v3; Assert.Equal( new[] { new KeyValuePair("Host", v1), - new KeyValuePair("custom", v2), + new KeyValuePair("Content-Length", v2), + new KeyValuePair("custom", v3), }, headers); } @@ -107,16 +124,18 @@ public void KeysAndValuesCanBeEnumerated() { IDictionary headers = new FrameRequestHeaders(); StringValues v1 = new[] { "localhost" }; - StringValues v2 = new[] { "value" }; + StringValues v2 = new[] { "0" }; + StringValues v3 = new[] { "value" }; headers["host"] = v1; - headers["custom"] = v2; + headers["Content-Length"] = v2; + headers["custom"] = v3; Assert.Equal( - new[] { "Host", "custom" }, + new[] { "Host", "Content-Length", "custom" }, headers.Keys); Assert.Equal( - new[] { v1, v2 }, + new[] { v1, v2, v3 }, headers.Values); } @@ -126,29 +145,50 @@ public void ContainsAndContainsKeyWork() IDictionary headers = new FrameRequestHeaders(); var kv1 = new KeyValuePair("host", new[] { "localhost" }); var kv2 = new KeyValuePair("custom", new[] { "value" }); + var kv3 = new KeyValuePair("Content-Length", new[] { "0" }); var kv1b = new KeyValuePair("host", new[] { "not-localhost" }); var kv2b = new KeyValuePair("custom", new[] { "not-value" }); + var kv3b = new KeyValuePair("Content-Length", new[] { "1" }); Assert.False(headers.ContainsKey("host")); Assert.False(headers.ContainsKey("custom")); + Assert.False(headers.ContainsKey("Content-Length")); Assert.False(headers.Contains(kv1)); Assert.False(headers.Contains(kv2)); + Assert.False(headers.Contains(kv3)); headers["host"] = kv1.Value; Assert.True(headers.ContainsKey("host")); Assert.False(headers.ContainsKey("custom")); + Assert.False(headers.ContainsKey("Content-Length")); Assert.True(headers.Contains(kv1)); Assert.False(headers.Contains(kv2)); + Assert.False(headers.Contains(kv3)); Assert.False(headers.Contains(kv1b)); Assert.False(headers.Contains(kv2b)); + Assert.False(headers.Contains(kv3b)); headers["custom"] = kv2.Value; Assert.True(headers.ContainsKey("host")); Assert.True(headers.ContainsKey("custom")); + Assert.False(headers.ContainsKey("Content-Length")); + Assert.True(headers.Contains(kv1)); + Assert.True(headers.Contains(kv2)); + Assert.False(headers.Contains(kv3)); + Assert.False(headers.Contains(kv1b)); + Assert.False(headers.Contains(kv2b)); + Assert.False(headers.Contains(kv3b)); + + headers["Content-Length"] = kv3.Value; + Assert.True(headers.ContainsKey("host")); + Assert.True(headers.ContainsKey("custom")); + Assert.True(headers.ContainsKey("Content-Length")); Assert.True(headers.Contains(kv1)); Assert.True(headers.Contains(kv2)); + Assert.True(headers.Contains(kv3)); Assert.False(headers.Contains(kv1b)); Assert.False(headers.Contains(kv2b)); + Assert.False(headers.Contains(kv3b)); } [Fact] @@ -159,16 +199,21 @@ public void AddWorksLikeSetAndThrowsIfKeyExists() StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); + headers.Add("Content-Length", new[] { "0" }); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); Assert.Throws(() => headers.Add("host", new[] { "localhost" })); Assert.Throws(() => headers.Add("custom", new[] { "value" })); + Assert.Throws(() => headers.Add("Content-Length", new[] { "0" })); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -177,17 +222,20 @@ public void ClearRemovesAllHeaders() IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); + headers.Add("Content-Length", new[] { "0" }); StringValues value; - Assert.Equal(2, headers.Count); + Assert.Equal(3, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); headers.Clear(); Assert.Equal(0, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -196,25 +244,36 @@ public void RemoveTakesHeadersOutOfDictionary() IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); + headers.Add("Content-Length", new[] { "0" }); StringValues value; - Assert.Equal(2, headers.Count); + Assert.Equal(3, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); Assert.True(headers.Remove("host")); Assert.False(headers.Remove("host")); - Assert.Equal(1, headers.Count); + Assert.Equal(2, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.Remove("custom")); Assert.False(headers.Remove("custom")); + Assert.Equal(1, headers.Count); + Assert.False(headers.TryGetValue("host", out value)); + Assert.False(headers.TryGetValue("custom", out value)); + Assert.True(headers.TryGetValue("Content-Length", out value)); + + Assert.True(headers.Remove("Content-Length")); + Assert.False(headers.Remove("Content-Length")); + Assert.Equal(0, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); + Assert.False(headers.TryGetValue("Content-Length", out value)); } [Fact] @@ -222,9 +281,10 @@ public void CopyToMovesDataIntoArray() { IDictionary headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); + headers.Add("Content-Length", new[] { "0" }); headers.Add("custom", new[] { "value" }); - var entries = new KeyValuePair[4]; + var entries = new KeyValuePair[5]; headers.CopyTo(entries, 1); Assert.Null(entries[0].Key); @@ -233,11 +293,14 @@ public void CopyToMovesDataIntoArray() Assert.Equal("Host", entries[1].Key); Assert.Equal(new[] { "localhost" }, entries[1].Value); - Assert.Equal("custom", entries[2].Key); - Assert.Equal(new[] { "value" }, entries[2].Value); + Assert.Equal("Content-Length", entries[2].Key); + Assert.Equal(new[] { "0" }, entries[2].Value); - Assert.Null(entries[3].Key); - Assert.Equal(new StringValues(), entries[0].Value); + Assert.Equal("custom", entries[3].Key); + Assert.Equal(new[] { "value" }, entries[3].Value); + + Assert.Null(entries[4].Key); + Assert.Equal(new StringValues(), entries[4].Value); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs index 55ec8ee48..b3dee3d0c 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/FrameResponseHeadersTests.cs @@ -10,8 +10,10 @@ using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; using Xunit; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.KestrelTests { @@ -173,16 +175,6 @@ public void ThrowsWhenSettingContentLengthToNonNumericValue(string contentLength Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); } - [Theory] - [MemberData(nameof(BadContentLengths))] - public void ThrowsWhenSettingRawContentLengthToNonNumericValue(string contentLength) - { - var headers = new FrameResponseHeaders(); - - var exception = Assert.Throws(() => headers.SetRawContentLength(contentLength, Encoding.ASCII.GetBytes(contentLength))); - Assert.Equal($"Invalid Content-Length: \"{contentLength}\". Value must be a positive integral number.", exception.Message); - } - [Theory] [MemberData(nameof(BadContentLengths))] public void ThrowsWhenAssigningHeaderContentLengthToNonNumericValue(string contentLength) @@ -201,7 +193,7 @@ public void ContentLengthValueCanBeReadAsLongAfterAddingHeader(string contentLen var dictionary = (IDictionary)headers; dictionary.Add("Content-Length", contentLength); - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.ContentLength); } [Theory] @@ -212,17 +204,7 @@ public void ContentLengthValueCanBeReadAsLongAfterSettingHeader(string contentLe var dictionary = (IDictionary)headers; dictionary["Content-Length"] = contentLength; - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); - } - - [Theory] - [MemberData(nameof(GoodContentLengths))] - public void ContentLengthValueCanBeReadAsLongAfterSettingRawHeader(string contentLength) - { - var headers = new FrameResponseHeaders(); - headers.SetRawContentLength(contentLength, Encoding.ASCII.GetBytes(contentLength)); - - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.ContentLength); } [Theory] @@ -232,7 +214,7 @@ public void ContentLengthValueCanBeReadAsLongAfterAssigningHeader(string content var headers = new FrameResponseHeaders(); headers.HeaderContentLength = contentLength; - Assert.Equal(ParseLong(contentLength), headers.HeaderContentLengthValue); + Assert.Equal(ParseLong(contentLength), headers.ContentLength); } [Fact] @@ -244,7 +226,7 @@ public void ContentLengthValueClearedWhenHeaderIsRemoved() dictionary.Remove("Content-Length"); - Assert.Equal(null, headers.HeaderContentLengthValue); + Assert.Equal(null, headers.ContentLength); } [Fact] @@ -256,7 +238,7 @@ public void ContentLengthValueClearedWhenHeadersCleared() dictionary.Clear(); - Assert.Equal(null, headers.HeaderContentLengthValue); + Assert.Equal(null, headers.ContentLength); } private static long ParseLong(string value) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs index 1db21257a..1239cfa99 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIteratorTests.cs @@ -1214,6 +1214,86 @@ public void TestGetAsciiStringEscaped(string input, string expected, int maxChar } } + [Fact] + public void CorrectContentLengthsOutput() + { + using (var pool = new MemoryPool()) + { + var block = pool.Lease(); + try + { + for (var i = 0u; i <= 9u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)(i + '0')); + Assert.Equal(block.End, block.Start + 1); + Assert.Equal(iter.Index, block.End); + } + for (var i = 10u; i <= 99u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)((i / 10) + '0')); + Assert.Equal(block.Array[block.Start + 1], (byte)((i % 10) + '0')); + + Assert.Equal(block.End, block.Start + 2); + Assert.Equal(iter.Index, block.End); + } + for (var i = 100u; i <= 999u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)((i / 100) + '0')); + Assert.Equal(block.Array[block.Start + 1], (byte)(((i % 100) / 10) + '0')); + Assert.Equal(block.Array[block.Start + 2], (byte)((i % 10) + '0')); + + Assert.Equal(block.End, block.Start + 3); + Assert.Equal(iter.Index, block.End); + } + for (var i = 1000u; i <= 9999u; i++) + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(i); + + Assert.Equal(block.Array[block.Start], (byte)((i / 1000) + '0')); + Assert.Equal(block.Array[block.Start + 1], (byte)(((i % 1000) / 100) + '0')); + Assert.Equal(block.Array[block.Start + 2], (byte)(((i % 100) / 10) + '0')); + Assert.Equal(block.Array[block.Start + 3], (byte)((i % 10) + '0')); + + Assert.Equal(block.End, block.Start + 4); + Assert.Equal(iter.Index, block.End); + } + { + block.Reset(); + var iter = new MemoryPoolIterator(block); + iter.CopyFromNumeric(ulong.MaxValue); + + var outputBytes = Encoding.ASCII.GetBytes(ulong.MaxValue.ToString("0")); + + for (var i = 0; i < outputBytes.Length; i++) + { + Assert.Equal(block.Array[block.Start + i], outputBytes[i]); + } + + Assert.Equal(block.End, block.Start + outputBytes.Length); + Assert.Equal(iter.Index, block.End); + } + } + finally + { + pool.Return(block); + } + } + } + private delegate bool GetKnownString(MemoryPoolIterator iter, out string result); private void TestKnownStringsInterning(string input, string expected, GetKnownString action) diff --git a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs index bd0c24aa0..96cc6a350 100644 --- a/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; @@ -19,47 +20,41 @@ static string If(bool condition, Func formatter) return condition ? formatter() : ""; } - static string AppendSwitch(IEnumerable> values, string className, bool handleUnknown = false) => - $@"fixed (byte* ptr = &keyBytes[keyOffset]) - {{ - var pUB = ptr; - var pUL = (ulong*)pUB; + static string AppendSwitch(IEnumerable> values, string className) => + $@"var pUL = (ulong*)pUB; var pUI = (uint*)pUB; var pUS = (ushort*)pUB; + var stringValue = new StringValues(value); switch (keyLength) {{{Each(values, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" if ({header.EqualIgnoreCaseBytes()}) - {{ + {{{(header.Identifier == "ContentLength" ? $@" + if (_contentLength.HasValue) + {{ + ThrowMultipleContentLengthsException(); + }} + else + {{ + _contentLength = ParseContentLength(value); + }} + return;" : $@" if ({header.TestBit()}) {{ _headers._{header.Identifier} = AppendValue(_headers._{header.Identifier}, value); }} else - {{{If(className == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{ {header.SetBit()}; - _headers._{header.Identifier} = new StringValues(value);{(header.EnhancedSetter == false ? "" : $@" + _headers._{header.Identifier} = stringValue;{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} }} - return; + return;")} }} ")}}} break; - ")}}} - - {(handleUnknown ? $@" - key = new string('\0', keyLength); - fixed(char *keyBuffer = key) - {{ - if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) - {{ - throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName); - }} - }} - ": "")} - }}"; + ")}}}"; class KnownHeader { @@ -72,7 +67,10 @@ class KnownHeader public int BytesCount { get; set; } public bool EnhancedSetter { get; set; } public bool PrimaryHeader { get; set; } - public string TestBit() => $"((_bits & {1L << Index}L) != 0)"; + public string TestBit() => $"(_bits & {1L << Index}L) != 0"; + public string TestTempBit() => $"(tempBits & {1L << Index}L) != 0"; + public string TestNotTempBit() => $"(tempBits & ~{1L << Index}L) == 0"; + public string TestNotBit() => $"(_bits & {1L << Index}L) == 0"; public string SetBit() => $"_bits |= {1L << Index}L"; public string ClearBit() => $"_bits &= ~{1L << Index}L"; @@ -135,7 +133,6 @@ public static string GeneratedFile() { "Connection", "Date", - "Content-Length", "Content-Type", "Server", }; @@ -152,7 +149,6 @@ public static string GeneratedFile() "Via", "Warning", "Allow", - "Content-Length", "Content-Type", "Content-Encoding", "Content-Language", @@ -192,19 +188,30 @@ public static string GeneratedFile() "TE", "Translate", "User-Agent", - }).Concat(corsRequestHeaders).Select((header, index) => new KnownHeader + }) + .Concat(corsRequestHeaders) + .Select((header, index) => new KnownHeader { Name = header, Index = index, PrimaryHeader = requestPrimaryHeaders.Contains(header) - }).ToArray(); + }) + .Concat(new[] { new KnownHeader + { + Name = "Content-Length", + Index = -1, + PrimaryHeader = requestPrimaryHeaders.Contains("Content-Length") + }}) + .ToArray(); + Debug.Assert(requestHeaders.Length <= 64); + Debug.Assert(requestHeaders.Max(x => x.Index) <= 62); + var enhancedHeaders = new[] { "Connection", "Server", "Date", - "Transfer-Encoding", - "Content-Length", + "Transfer-Encoding" }; // http://www.w3.org/TR/cors/#syntax var corsResponseHeaders = new[] @@ -228,13 +235,27 @@ public static string GeneratedFile() "Set-Cookie", "Vary", "WWW-Authenticate", - }).Concat(corsResponseHeaders).Select((header, index) => new KnownHeader + }) + .Concat(corsResponseHeaders) + .Select((header, index) => new KnownHeader { Name = header, Index = index, EnhancedSetter = enhancedHeaders.Contains(header), PrimaryHeader = responsePrimaryHeaders.Contains(header) - }).ToArray(); + }) + .Concat(new[] { new KnownHeader + { + Name = "Content-Length", + Index = -1, + EnhancedSetter = enhancedHeaders.Contains("Content-Length"), + PrimaryHeader = responsePrimaryHeaders.Contains("Content-Length") + }}) + .ToArray(); + // 63 for reponseHeaders as it steals one bit for Content-Length in CopyTo(ref MemoryPoolIterator output) + Debug.Assert(responseHeaders.Length <= 63); + Debug.Assert(responseHeaders.Max(x => x.Index) <= 62); + var loops = new[] { new @@ -269,6 +290,7 @@ public static string GeneratedFile() using System.Collections.Generic; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http {{ @@ -286,61 +308,48 @@ public partial class {loop.ClassName} private HeaderReferences _headers; {Each(loop.Headers, header => $@" public StringValues Header{header.Identifier} - {{ + {{{(header.Identifier == "ContentLength" ? $@" get {{ + StringValues value; + if (_contentLength.HasValue) + {{ + value = new StringValues(HeaderUtilities.FormatInt64(_contentLength.Value)); + }} + return value; + }} + set + {{ + _contentLength = ParseContentLength(value); + }}" : $@" + get + {{ + StringValues value; if ({header.TestBit()}) {{ - return _headers._{header.Identifier}; + value = _headers._{header.Identifier}; }} - return StringValues.Empty; + return value; }} set - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{ {header.SetBit()}; _headers._{header.Identifier} = value; {(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} - }} + }}")} }}")} - {Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" +{Each(loop.Headers.Where(header => header.EnhancedSetter), header => $@" public void SetRaw{header.Identifier}(StringValues value, byte[] raw) - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{ {header.SetBit()}; _headers._{header.Identifier} = value; _headers._raw{header.Identifier} = raw; }}")} protected override int GetCountFast() {{ - return BitCount(_bits) + (MaybeUnknown?.Count ?? 0); - }} - protected override StringValues GetValueFast(string key) - {{ - switch (key.Length) - {{{Each(loop.HeadersByLength, byLength => $@" - case {byLength.Key}: - {{{Each(byLength, header => $@" - if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ - if ({header.TestBit()}) - {{ - return _headers._{header.Identifier}; - }} - else - {{ - ThrowKeyNotFoundException(); - }} - }} - ")}}} - break; -")}}} - if (MaybeUnknown == null) - {{ - ThrowKeyNotFoundException(); - }} - return MaybeUnknown[key]; + return (_contentLength.HasValue ? 1 : 0 ) + BitCount(_bits) + (MaybeUnknown?.Count ?? 0); }} + protected override bool TryGetValueFast(string key, out StringValues value) {{ switch (key.Length) @@ -348,71 +357,83 @@ protected override bool TryGetValueFast(string key, out StringValues value) case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ + {{{(header.Identifier == "ContentLength" ? @" + if (_contentLength.HasValue) + { + value = HeaderUtilities.FormatInt64(_contentLength.Value); + return true; + } + return false;" : $@" if ({header.TestBit()}) {{ value = _headers._{header.Identifier}; return true; }} - else - {{ - value = StringValues.Empty; - return false; - }} - }} - ")}}} - break; -")}}} - value = StringValues.Empty; + return false;")} + }}")} + }} + break;")} + }} + return MaybeUnknown?.TryGetValue(key, out value) ?? false; }} + protected override void SetValueFast(string key, StringValues value) - {{ - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(value);" : "")} + {{{(loop.ClassName == "FrameResponseHeaders" ? @" + ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} + {{{(header.Identifier == "ContentLength" ? $@" + _contentLength = ParseContentLength(value.ToString());" : $@" {header.SetBit()}; _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" - _headers._raw{header.Identifier} = null;")} + _headers._raw{header.Identifier} = null;")}")} return; - }} - ")}}} - break; -")}}} - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(key);" : "")} - Unknown[key] = value; + }}")} + }} + break;")} + }} + + SetValueUnknown(key, value); }} - protected override void AddValueFast(string key, StringValues value) - {{ - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(value);" : "")} + + protected override bool AddValueFast(string key, StringValues value) + {{{(loop.ClassName == "FrameResponseHeaders" ? @" + ValidateHeaderCharacters(value);" : "")} switch (key.Length) {{{Each(loop.HeadersByLength, byLength => $@" case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ - if ({header.TestBit()}) + {{{(header.Identifier == "ContentLength" ? $@" + if (!_contentLength.HasValue) {{ - ThrowDuplicateKeyException(); - }}{ - If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = ParseContentLength(value);")} - {header.SetBit()}; - _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" - _headers._raw{header.Identifier} = null;")} - return; - }} - ")}}} - break; - ")}}} - {(loop.ClassName == "FrameResponseHeaders" ? "ValidateHeaderCharacters(key);" : "")} + _contentLength = ParseContentLength(value); + return true; + }} + return false;" : $@" + if ({header.TestNotBit()}) + {{ + {header.SetBit()}; + _headers._{header.Identifier} = value;{(header.EnhancedSetter == false ? "" : $@" + _headers._raw{header.Identifier} = null;")} + return true; + }} + return false;")} + }}")} + }} + break;")} + }} +{(loop.ClassName == "FrameResponseHeaders" ? @" + ValidateHeaderCharacters(key);" : "")} Unknown.Add(key, value); + // Return true, above will throw and exit for false + return true; }} + protected override bool RemoveFast(string key) {{ switch (key.Length) @@ -420,74 +441,88 @@ protected override bool RemoveFast(string key) case {byLength.Key}: {{{Each(byLength, header => $@" if (""{header.Name}"".Equals(key, StringComparison.OrdinalIgnoreCase)) - {{ + {{{(header.Identifier == "ContentLength" ? @" + if (_contentLength.HasValue) + { + _contentLength = null; + return true; + } + return false;" : $@" if ({header.TestBit()}) - {{{If(loop.ClassName == "FrameResponseHeaders" && header.Identifier == "ContentLength", () => @" - _contentLength = null;")} + {{ {header.ClearBit()}; - _headers._{header.Identifier} = StringValues.Empty;{(header.EnhancedSetter == false ? "" : $@" + _headers._{header.Identifier} = default(StringValues);{(header.EnhancedSetter == false ? "" : $@" _headers._raw{header.Identifier} = null;")} return true; }} - else - {{ - return false; - }} - }} - ")}}} - break; - ")}}} + return false;")} + }}")} + }} + break;")} + }} + return MaybeUnknown?.Remove(key) ?? false; }} + protected override void ClearFast() - {{ + {{ MaybeUnknown?.Clear(); - {(loop.ClassName == "FrameResponseHeaders" ? "_contentLength = null;" : "")} - if(FrameHeaders.BitCount(_bits) > 12) + _contentLength = null; + var tempBits = _bits; + _bits = 0; + if(FrameHeaders.BitCount(tempBits) > 12) {{ _headers = default(HeaderReferences); - _bits = 0; return; }} - {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" - if ({header.TestBit()}) + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" + if ({header.TestTempBit()}) {{ _headers._{header.Identifier} = default(StringValues); - {header.ClearBit()}; - if(_bits == 0) + if({header.TestNotTempBit()}) {{ return; }} + tempBits &= ~{1L << header.Index}L; }} ")} }} - protected override void CopyToFast(KeyValuePair[] array, int arrayIndex) + protected override bool CopyToFast(KeyValuePair[] array, int arrayIndex) {{ if (arrayIndex < 0) {{ - ThrowArgumentException(); + return false; }} - {Each(loop.Headers, header => $@" + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@" if ({header.TestBit()}) {{ if (arrayIndex == array.Length) {{ - ThrowArgumentException(); + return false; }} - array[arrayIndex] = new KeyValuePair(""{header.Name}"", _headers._{header.Identifier}); ++arrayIndex; + }}")} + if (_contentLength.HasValue) + {{ + if (arrayIndex == array.Length) + {{ + return false; + }} + array[arrayIndex] = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatInt64(_contentLength.Value)); + ++arrayIndex; }} - ")} ((ICollection>)MaybeUnknown)?.CopyTo(array, arrayIndex); + + return true; }} {(loop.ClassName == "FrameResponseHeaders" ? $@" protected void CopyToFast(ref MemoryPoolIterator output) {{ - var tempBits = _bits; - {Each(loop.Headers.OrderBy(h => !h.PrimaryHeader), header => $@" - if ({header.TestBit()}) + var tempBits = _bits | (_contentLength.HasValue ? {1L << 63}L : 0); + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength").OrderBy(h => !h.PrimaryHeader), header => $@" + if ({header.TestTempBit()}) {{ {(header.EnhancedSetter == false ? "" : $@" if (_headers._raw{header.Identifier} != null) {{ @@ -507,35 +542,46 @@ protected void CopyToFast(ref MemoryPoolIterator output) }} }} + if({header.TestNotTempBit()}) + {{ + return; + }} tempBits &= ~{1L << header.Index}L; - if(tempBits == 0) + }}{(header.Identifier == "Server" ? $@" + if ((tempBits & {1L << 63}L) != 0) + {{ + output.CopyFrom(_headerBytes, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesOffset}, {loop.Headers.First(x => x.Identifier == "ContentLength").BytesCount}); + output.CopyFromNumeric((ulong)ContentLength.Value); + + if((tempBits & ~{1L << 63}L) == 0) {{ return; }} - }} - ")} - }} - - " : "")} + tempBits &= ~{1L << 63}L; + }}" : "")}")} + }}" : "")} {(loop.ClassName == "FrameRequestHeaders" ? $@" public unsafe void Append(byte[] keyBytes, int keyOffset, int keyLength, string value) {{ - {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - - AppendNonPrimaryHeaders(keyBytes, keyOffset, keyLength, value); + fixed (byte* ptr = &keyBytes[keyOffset]) + {{ + var pUB = ptr; + {AppendSwitch(loop.Headers.Where(h => h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} + + AppendNonPrimaryHeaders(ptr, keyOffset, keyLength, value); + }} }} - private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int keyLength, string value) + private unsafe void AppendNonPrimaryHeaders(byte* pKeyBytes, int keyOffset, int keyLength, string value) {{ - string key; - {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName, true)} + var pUB = pKeyBytes; + {AppendSwitch(loop.Headers.Where(h => !h.PrimaryHeader).GroupBy(x => x.Name.Length), loop.ClassName)} - StringValues existing; - Unknown.TryGetValue(key, out existing); - Unknown[key] = AppendValue(existing, value); + AppendUnknownHeaders(pKeyBytes, keyLength, value); }}" : "")} + private struct HeaderReferences - {{{Each(loop.Headers, header => @" + {{{Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => @" public StringValues _" + header.Identifier + ";")} {Each(loop.Headers.Where(header => header.EnhancedSetter), header => @" public byte[] _raw" + header.Identifier + ";")} @@ -547,14 +593,16 @@ public bool MoveNext() {{ switch (_state) {{ - {Each(loop.Headers, header => $@" - case {header.Index}: - goto state{header.Index}; + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@" + case {header.Index}: + goto state{header.Index}; ")} + case {loop.Headers.Count()}: + goto state{loop.Headers.Count()}; default: goto state_default; }} - {Each(loop.Headers, header => $@" + {Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@" state{header.Index}: if ({header.TestBit()}) {{ @@ -563,6 +611,13 @@ public bool MoveNext() return true; }} ")} + state{loop.Headers.Count()}: + if (_collection._contentLength.HasValue) + {{ + _current = new KeyValuePair(""Content-Length"", HeaderUtilities.FormatInt64(_collection._contentLength.Value)); + _state = {loop.Headers.Count() + 1}; + return true; + }} state_default: if (!_hasUnknown || !_unknownEnumerator.MoveNext()) {{