Skip to content
代码片段 群组 项目
未验证 提交 eab9005e 编辑于 作者: Youssef Victor's avatar Youssef Victor 提交者: GitHub
浏览文件

Make H3StaticTable static class (#21705)

* Update H3StaticTable.cs

* Update QPackEncoder.cs

* Update Http3TestBase.cs

* Update EncoderStreamReader.cs

* Update QPackDecoder.cs

* Update Http3Stream.cs

* Use s_ prefix for static fields
上级 bf099ab5
No related branches found
No related tags found
无相关合并请求
......@@ -116,13 +116,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3
public void OnStaticIndexedHeader(int index)
{
var knownHeader = H3StaticTable.Instance[index];
var knownHeader = H3StaticTable.GetHeaderFieldAt(index);
OnHeader(knownHeader.Name, knownHeader.Value);
}
public void OnStaticIndexedHeader(int index, ReadOnlySpan<byte> value)
{
var knownHeader = H3StaticTable.Instance[index];
var knownHeader = H3StaticTable.GetHeaderFieldAt(index);
OnHeader(knownHeader.Name, value);
}
......
......@@ -322,7 +322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.QPack
{
try
{
return _s ? H3StaticTable.Instance[index] : _dynamicTable[index];
return _s ? H3StaticTable.GetHeaderFieldAt(index) : _dynamicTable[index];
}
catch (IndexOutOfRangeException ex)
{
......
......@@ -355,13 +355,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
public void OnStaticIndexedHeader(int index)
{
var knownHeader = H3StaticTable.Instance[index];
var knownHeader = H3StaticTable.GetHeaderFieldAt(index);
_decodedHeaders[((Span<byte>)knownHeader.Name).GetAsciiStringNonNullCharacters()] = HttpUtilities.GetAsciiOrUTF8StringNonNullCharacters(knownHeader.Value);
}
public void OnStaticIndexedHeader(int index, ReadOnlySpan<byte> value)
{
_decodedHeaders[((Span<byte>)H3StaticTable.Instance[index].Name).GetAsciiStringNonNullCharacters()] = value.GetAsciiOrUTF8StringNonNullCharacters();
_decodedHeaders[((Span<byte>)H3StaticTable.GetHeaderFieldAt(index).Name).GetAsciiStringNonNullCharacters()] = value.GetAsciiOrUTF8StringNonNullCharacters();
}
internal async Task WaitForStreamErrorAsync(Http3ErrorCode protocolError, string expectedErrorMessage)
......
......@@ -7,10 +7,9 @@ using System.Text;
namespace System.Net.Http.QPack
{
// TODO: make class static.
internal class H3StaticTable
internal static class H3StaticTable
{
private readonly Dictionary<int, int> _statusIndex = new Dictionary<int, int>
private static readonly Dictionary<int, int> s_statusIndex = new Dictionary<int, int>
{
[103] = 24,
[200] = 25,
......@@ -28,7 +27,7 @@ namespace System.Net.Http.QPack
[500] = 71,
};
private readonly Dictionary<HttpMethod, int> _methodIndex = new Dictionary<HttpMethod, int>
private static readonly Dictionary<HttpMethod, int> s_methodIndex = new Dictionary<HttpMethod, int>
{
// TODO connect is internal to system.net.http
[HttpMethod.Delete] = 16,
......@@ -39,21 +38,15 @@ namespace System.Net.Http.QPack
[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<int, int> StatusIndex => _statusIndex;
public IReadOnlyDictionary<HttpMethod, int> MethodIndex => _methodIndex;
public static IReadOnlyDictionary<int, int> StatusIndex => s_statusIndex;
public static IReadOnlyDictionary<HttpMethod, int> 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
......
......@@ -413,7 +413,7 @@ namespace System.Net.Http.QPack
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;
......
......@@ -416,7 +416,7 @@ namespace System.Net.Http.QPack
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
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册