From c5937b3bba67ac813c76c9125142d2d88fc365ed Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 11 May 2020 18:22:55 +0200 Subject: [PATCH 1/4] Make class as static --- .../aspnetcore/Http3/QPack/H3StaticTable.cs | 23 +++++++------------ .../aspnetcore/Http3/QPack/QPackDecoder.cs | 2 +- .../aspnetcore/Http3/QPack/QPackEncoder.cs | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) 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..cea98ffcf2d20 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 _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 _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 static int Count => _staticTable.Length; - public HeaderField this[int index] => _staticTable[index]; + public static HeaderField this[int index] => _staticTable[index]; // TODO: just use Dictionary directly to avoid interface dispatch. - public IReadOnlyDictionary StatusIndex => _statusIndex; - public IReadOnlyDictionary MethodIndex => _methodIndex; + public static IReadOnlyDictionary StatusIndex => _statusIndex; + public static IReadOnlyDictionary MethodIndex => _methodIndex; - private readonly HeaderField[] _staticTable = new HeaderField[] + private static readonly HeaderField[] _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 From 3688c871daeecc9a208f12eff0ae1a876bb6b947 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 11 May 2020 18:24:25 +0200 Subject: [PATCH 2/4] Update H3StaticTable.cs --- .../src/System/Net/Http/aspnetcore/Http3/QPack/H3StaticTable.cs | 2 -- 1 file changed, 2 deletions(-) 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 cea98ffcf2d20..29b132083618f 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 @@ -40,8 +40,6 @@ internal static class H3StaticTable public static int Count => _staticTable.Length; - public static HeaderField this[int index] => _staticTable[index]; - // TODO: just use Dictionary directly to avoid interface dispatch. public static IReadOnlyDictionary StatusIndex => _statusIndex; public static IReadOnlyDictionary MethodIndex => _methodIndex; From 95d6e8baf51f3728e91d79f95d1a71d734d3c707 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 11 May 2020 20:44:47 +0200 Subject: [PATCH 3/4] Update H3StaticTable.cs --- .../src/System/Net/Http/aspnetcore/Http3/QPack/H3StaticTable.cs | 2 ++ 1 file changed, 2 insertions(+) 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 29b132083618f..5ed89a865d38e 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 @@ -44,6 +44,8 @@ internal static class H3StaticTable public static IReadOnlyDictionary StatusIndex => _statusIndex; public static IReadOnlyDictionary MethodIndex => _methodIndex; + public static HeaderField GetHeaderFieldAt(int index) => _staticTable[index]; + private static readonly HeaderField[] _staticTable = new HeaderField[] { CreateHeaderField(":authority", ""), // 0 From 6b8b194a5d42acd8f8ba85b02999f33955333e04 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Tue, 12 May 2020 08:38:01 +0200 Subject: [PATCH 4/4] Update H3StaticTable.cs --- .../Http/aspnetcore/Http3/QPack/H3StaticTable.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 5ed89a865d38e..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 @@ -9,7 +9,7 @@ namespace System.Net.Http.QPack { internal static class H3StaticTable { - private static readonly Dictionary _statusIndex = new Dictionary + private static readonly Dictionary s_statusIndex = new Dictionary { [103] = 24, [200] = 25, @@ -27,7 +27,7 @@ internal static class H3StaticTable [500] = 71, }; - private static readonly Dictionary _methodIndex = new Dictionary + private static readonly Dictionary s_methodIndex = new Dictionary { // TODO connect is internal to system.net.http [HttpMethod.Delete] = 16, @@ -38,15 +38,15 @@ internal static class H3StaticTable [HttpMethod.Put] = 21, }; - public static int Count => _staticTable.Length; + public static int Count => s_staticTable.Length; // TODO: just use Dictionary directly to avoid interface dispatch. - public static IReadOnlyDictionary StatusIndex => _statusIndex; - public static IReadOnlyDictionary MethodIndex => _methodIndex; + public static IReadOnlyDictionary StatusIndex => s_statusIndex; + public static IReadOnlyDictionary MethodIndex => s_methodIndex; - public static HeaderField GetHeaderFieldAt(int index) => _staticTable[index]; + public static HeaderField GetHeaderFieldAt(int index) => s_staticTable[index]; - private static readonly HeaderField[] _staticTable = new HeaderField[] + private static readonly HeaderField[] s_staticTable = new HeaderField[] { CreateHeaderField(":authority", ""), // 0 CreateHeaderField(":path", "/"), // 1