| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Text; |
| | | 6 | | |
| | | 7 | | namespace System.Net.Http.Headers |
| | | 8 | | { |
| | | 9 | | internal sealed partial class KnownHeader |
| | | 10 | | { |
| | | 11 | | public KnownHeader(string name, string[]? knownValues = null, int? http2StaticTableIndex = null, int? http3Stati |
| | 39 | 12 | | : this(name, HttpHeaderType.Custom, parser: null, knownValues, http2StaticTableIndex, http3StaticTableIndex) |
| | 78 | 13 | | { } |
| | | 14 | | |
| | 98 | 15 | | public KnownHeader(string name, HttpHeaderType headerType, HttpHeaderParser? parser, string[]? knownValues = nul |
| | 98 | 16 | | { |
| | 98 | 17 | | Debug.Assert(!string.IsNullOrEmpty(name)); |
| | 98 | 18 | | Debug.Assert(name[0] == ':' || HttpRuleParser.IsToken(name)); |
| | | 19 | | |
| | 98 | 20 | | Name = name; |
| | 98 | 21 | | HeaderType = headerType; |
| | 98 | 22 | | Parser = parser; |
| | 98 | 23 | | KnownValues = knownValues; |
| | | 24 | | |
| | 98 | 25 | | Initialize(http2StaticTableIndex, http3StaticTableIndex); |
| | | 26 | | |
| | 98 | 27 | | var asciiBytesWithColonSpace = new byte[name.Length + 2]; // + 2 for ':' and ' ' |
| | 98 | 28 | | int asciiBytes = Encoding.ASCII.GetBytes(name, asciiBytesWithColonSpace); |
| | 98 | 29 | | Debug.Assert(asciiBytes == name.Length); |
| | 98 | 30 | | asciiBytesWithColonSpace[asciiBytesWithColonSpace.Length - 2] = (byte)':'; |
| | 98 | 31 | | asciiBytesWithColonSpace[asciiBytesWithColonSpace.Length - 1] = (byte)' '; |
| | 98 | 32 | | AsciiBytesWithColonSpace = asciiBytesWithColonSpace; |
| | 98 | 33 | | } |
| | | 34 | | |
| | | 35 | | partial void Initialize(int? http2StaticTableIndex, int? http3StaticTableIndex); |
| | | 36 | | |
| | 132968 | 37 | | public string Name { get; } |
| | 964765 | 38 | | public HttpHeaderParser? Parser { get; } |
| | 110362 | 39 | | public HttpHeaderType HeaderType { get; } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// If a raw string is a known value, this instance will be returned rather than allocating a new string. |
| | | 43 | | /// </summary> |
| | 0 | 44 | | public string[]? KnownValues { get; } |
| | 0 | 45 | | public byte[] AsciiBytesWithColonSpace { get; } |
| | 0 | 46 | | public HeaderDescriptor Descriptor => new HeaderDescriptor(this); |
| | | 47 | | } |
| | | 48 | | } |