diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/H3StaticTable.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/H3StaticTable.cs index 13fc509cc6365..c4ca224742b12 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/H3StaticTable.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/H3StaticTable.cs @@ -7,10 +7,9 @@ namespace System.Net.Http.QPack { - // TODO: make class static. - internal class H3StaticTable + internal static class H3StaticTable { - private readonly Dictionary _statusIndex = new Dictionary + private static readonly Dictionary s_statusIndex = new Dictionary { [103] = 24, [200] = 25, @@ -28,7 +27,7 @@ internal class H3StaticTable [500] = 71, }; - private readonly Dictionary _methodIndex = new Dictionary + private static readonly Dictionary s_methodIndex = new Dictionary { // TODO connect is internal to system.net.http [HttpMethod.Delete] = 16, @@ -39,21 +38,15 @@ internal class H3StaticTable [HttpMethod.Put] = 21, }; - private H3StaticTable() - { - } - - public static H3StaticTable Instance { get; } = new H3StaticTable(); - - public int Count => _staticTable.Length; - - public HeaderField this[int index] => _staticTable[index]; + public static int Count => s_staticTable.Length; // TODO: just use Dictionary directly to avoid interface dispatch. - public IReadOnlyDictionary StatusIndex => _statusIndex; - public IReadOnlyDictionary MethodIndex => _methodIndex; + public static IReadOnlyDictionary StatusIndex => s_statusIndex; + public static IReadOnlyDictionary MethodIndex => s_methodIndex; + + public static HeaderField GetHeaderFieldAt(int index) => s_staticTable[index]; - private readonly HeaderField[] _staticTable = new HeaderField[] + private static readonly HeaderField[] s_staticTable = new HeaderField[] { CreateHeaderField(":authority", ""), // 0 CreateHeaderField(":path", "/"), // 1 diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecoder.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecoder.cs index e3b85872ed755..0ac27cda1cb2e 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecoder.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackDecoder.cs @@ -413,7 +413,7 @@ private void ProcessHeaderValue(IHttpHeadersHandler handler) if (_index is int index) { - Debug.Assert(index >= 0 && index <= H3StaticTable.Instance.Count, $"The index should be a valid static index here. {nameof(QPackDecoder)} should have previously thrown if it read a dynamic index."); + Debug.Assert(index >= 0 && index <= H3StaticTable.Count, $"The index should be a valid static index here. {nameof(QPackDecoder)} should have previously thrown if it read a dynamic index."); handler.OnStaticIndexedHeader(index, headerValueSpan); _index = null; diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackEncoder.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackEncoder.cs index c956095910627..49cfd84633665 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackEncoder.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http3/QPack/QPackEncoder.cs @@ -416,7 +416,7 @@ private int EncodeStatusCode(int statusCode, Span buffer) case 404: case 500: // TODO this isn't safe, some index can be larger than 64. Encoded here! - buffer[0] = (byte)(0xC0 | H3StaticTable.Instance.StatusIndex[statusCode]); + buffer[0] = (byte)(0xC0 | H3StaticTable.StatusIndex[statusCode]); return 1; default: // Send as Literal Header Field Without Indexing - Indexed Name