From dfbae37e91c4744822018dde10cbd414c661c0b8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 15 Dec 2021 07:48:18 +1300 Subject: [PATCH] Rename IHttpHeadersHandler to IHttpStreamHeadersHandler (#62750) Co-authored-by: James Newton-King --- .../aspnetcore/Http2/Hpack/HPackDecoder.cs | 30 +++++++------- .../aspnetcore/Http3/QPack/QPackDecoder.cs | 40 +++++++++---------- .../Http/aspnetcore/IHttpHeadersHandler.cs | 31 -------------- .../aspnetcore/IHttpStreamHeadersHandler.cs | 14 +++++++ .../Common/tests/Common.Tests.csproj | 4 +- .../Net/aspnetcore/Http2/HPackDecoderTest.cs | 22 ++++++---- .../Net/aspnetcore/Http3/QPackDecoderTest.cs | 22 ++++++---- .../src/System.Net.Http.csproj | 4 +- .../SocketsHttpHandler/Http2Connection.cs | 15 +++---- .../Http/SocketsHttpHandler/Http2Stream.cs | 11 +++-- .../SocketsHttpHandler/Http3RequestStream.cs | 15 ++++--- .../UnitTests/HPack/HPackRoundtripTests.cs | 7 +++- .../System.Net.Http.Unit.Tests.csproj | 4 +- 13 files changed, 117 insertions(+), 102 deletions(-) delete mode 100644 src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpHeadersHandler.cs create mode 100644 src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpStreamHeadersHandler.cs diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecoder.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecoder.cs index c287478bbee7a..f9d8dc45b8b8e 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecoder.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/HPackDecoder.cs @@ -118,7 +118,7 @@ internal HPackDecoder(int maxDynamicTableSize, int maxHeadersLength, DynamicTabl _headerValueOctets = new byte[DefaultStringOctetsSize]; } - public void Decode(in ReadOnlySequence data, bool endHeaders, IHttpHeadersHandler handler) + public void Decode(in ReadOnlySequence data, bool endHeaders, IHttpStreamHeadersHandler handler) { foreach (ReadOnlyMemory segment in data) { @@ -128,13 +128,13 @@ public void Decode(in ReadOnlySequence data, bool endHeaders, IHttpHeaders CheckIncompleteHeaderBlock(endHeaders); } - public void Decode(ReadOnlySpan data, bool endHeaders, IHttpHeadersHandler handler) + public void Decode(ReadOnlySpan data, bool endHeaders, IHttpStreamHeadersHandler handler) { DecodeInternal(data, handler); CheckIncompleteHeaderBlock(endHeaders); } - private void DecodeInternal(ReadOnlySpan data, IHttpHeadersHandler handler) + private void DecodeInternal(ReadOnlySpan data, IHttpStreamHeadersHandler handler) { int currentIndex = 0; @@ -206,7 +206,7 @@ private void ParseDynamicTableSizeUpdate(ReadOnlySpan data, ref int curren } } - private void ParseHeaderValueLength(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderValueLength(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -236,7 +236,7 @@ private void ParseHeaderValueLength(ReadOnlySpan data, ref int currentInde } } - private void ParseHeaderNameLengthContinue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderNameLengthContinue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -249,7 +249,7 @@ private void ParseHeaderNameLengthContinue(ReadOnlySpan data, ref int curr } } - private void ParseHeaderValueLengthContinue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderValueLengthContinue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -261,7 +261,7 @@ private void ParseHeaderValueLengthContinue(ReadOnlySpan data, ref int cur } } - private void ParseHeaderFieldIndex(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderFieldIndex(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -269,7 +269,7 @@ private void ParseHeaderFieldIndex(ReadOnlySpan data, ref int currentIndex } } - private void ParseHeaderNameIndex(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderNameIndex(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -278,7 +278,7 @@ private void ParseHeaderNameIndex(ReadOnlySpan data, ref int currentIndex, } } - private void ParseHeaderNameLength(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderNameLength(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -304,7 +304,7 @@ private void ParseHeaderNameLength(ReadOnlySpan data, ref int currentIndex } } - private void Parse(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void Parse(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -388,7 +388,7 @@ private void Parse(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHa } } - private void ParseLiteralHeaderField(ReadOnlySpan data, ref int currentIndex, byte b, byte mask, byte indexPrefix, bool index, IHttpHeadersHandler handler) + private void ParseLiteralHeaderField(ReadOnlySpan data, ref int currentIndex, byte b, byte mask, byte indexPrefix, bool index, IHttpStreamHeadersHandler handler) { _headersObserved = true; @@ -415,7 +415,7 @@ private void ParseLiteralHeaderField(ReadOnlySpan data, ref int currentInd } } - private void ParseHeaderName(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderName(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { // Read remaining chars, up to the length of the current data int count = Math.Min(_stringLength - _stringIndex, data.Length - currentIndex); @@ -452,7 +452,7 @@ private void ParseHeaderName(ReadOnlySpan data, ref int currentIndex, IHtt } } - private void ParseHeaderValue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderValue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { // Read remaining chars, up to the length of the current data int count = Math.Min(_stringLength - _stringIndex, data.Length - currentIndex); @@ -496,7 +496,7 @@ private void CheckIncompleteHeaderBlock(bool endHeaders) } } - private void ProcessHeaderValue(ReadOnlySpan data, IHttpHeadersHandler handler) + private void ProcessHeaderValue(ReadOnlySpan data, IHttpStreamHeadersHandler handler) { ReadOnlySpan headerValueSpan = _headerValueRange == null ? _headerValueOctets.AsSpan(0, _headerValueLength) @@ -539,7 +539,7 @@ public void CompleteDecode() } } - private void OnIndexedHeaderField(int index, IHttpHeadersHandler handler) + private void OnIndexedHeaderField(int index, IHttpStreamHeadersHandler handler) { if (index <= H2StaticTable.Count) { 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 9b7e6a2716ec9..83e1b7f3a3b9f 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 @@ -163,7 +163,7 @@ public void Reset() _state = State.RequiredInsertCount; } - public void Decode(in ReadOnlySequence data, bool endHeaders, IHttpHeadersHandler handler) + public void Decode(in ReadOnlySequence data, bool endHeaders, IHttpStreamHeadersHandler handler) { foreach (ReadOnlyMemory segment in data) { @@ -172,13 +172,13 @@ public void Decode(in ReadOnlySequence data, bool endHeaders, IHttpHeaders CheckIncompleteHeaderBlock(endHeaders); } - public void Decode(ReadOnlySpan data, bool endHeaders, IHttpHeadersHandler handler) + public void Decode(ReadOnlySpan data, bool endHeaders, IHttpStreamHeadersHandler handler) { DecodeInternal(data, handler); CheckIncompleteHeaderBlock(endHeaders); } - private void DecodeInternal(ReadOnlySpan data, IHttpHeadersHandler handler) + private void DecodeInternal(ReadOnlySpan data, IHttpStreamHeadersHandler handler) { int currentIndex = 0; @@ -253,7 +253,7 @@ private void DecodeInternal(ReadOnlySpan data, IHttpHeadersHandler handler } } - private void ParseHeaderNameIndexPostBase(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderNameIndexPostBase(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -261,7 +261,7 @@ private void ParseHeaderNameIndexPostBase(ReadOnlySpan data, ref int curre } } - private void ParsePostBaseIndex(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParsePostBaseIndex(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -269,7 +269,7 @@ private void ParsePostBaseIndex(ReadOnlySpan data, ref int currentIndex, I } } - private void ParseHeaderNameLength(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderNameLength(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -282,7 +282,7 @@ private void ParseHeaderNameLength(ReadOnlySpan data, ref int currentIndex } } - private void ParseHeaderName(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderName(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { // Read remaining chars, up to the length of the current data int count = Math.Min(_stringLength - _stringIndex, data.Length - currentIndex); @@ -320,7 +320,7 @@ private void ParseHeaderName(ReadOnlySpan data, ref int currentIndex, IHtt } } - private void ParseHeaderFieldIndex(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderFieldIndex(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -328,7 +328,7 @@ private void ParseHeaderFieldIndex(ReadOnlySpan data, ref int currentIndex } } - private void ParseHeaderNameIndex(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderNameIndex(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -337,7 +337,7 @@ private void ParseHeaderNameIndex(ReadOnlySpan data, ref int currentIndex, } } - private void ParseHeaderValueLength(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderValueLength(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -367,7 +367,7 @@ private void ParseHeaderValueLength(ReadOnlySpan data, ref int currentInde } } - private void ParseHeaderValue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderValue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { // Read remaining chars, up to the length of the current data int count = Math.Min(_stringLength - _stringIndex, data.Length - currentIndex); @@ -404,7 +404,7 @@ private void ParseHeaderValue(ReadOnlySpan data, ref int currentIndex, IHt } } - private void ParseHeaderValueLengthContinue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseHeaderValueLengthContinue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -421,7 +421,7 @@ private void ParseHeaderValueLengthContinue(ReadOnlySpan data, ref int cur } } - private void ParseCompressedHeaders(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseCompressedHeaders(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -520,7 +520,7 @@ private void ParseCompressedHeaders(ReadOnlySpan data, ref int currentInde } } - private void ParseRequiredInsertCountContinue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseRequiredInsertCountContinue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -529,7 +529,7 @@ private void ParseRequiredInsertCountContinue(ReadOnlySpan data, ref int c } } - private void ParseBase(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseBase(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -549,7 +549,7 @@ private void ParseBase(ReadOnlySpan data, ref int currentIndex, IHttpHeade } } - private void ParseBaseContinue(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseBaseContinue(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (TryDecodeInteger(data, ref currentIndex, out int intResult)) { @@ -558,7 +558,7 @@ private void ParseBaseContinue(ReadOnlySpan data, ref int currentIndex, IH } } - private void ParseRequiredInsertCount(ReadOnlySpan data, ref int currentIndex, IHttpHeadersHandler handler) + private void ParseRequiredInsertCount(ReadOnlySpan data, ref int currentIndex, IHttpStreamHeadersHandler handler) { if (currentIndex < data.Length) { @@ -588,7 +588,7 @@ private void CheckIncompleteHeaderBlock(bool endHeaders) } } - private void ProcessHeaderValue(ReadOnlySpan data, IHttpHeadersHandler handler) + private void ProcessHeaderValue(ReadOnlySpan data, IHttpStreamHeadersHandler handler) { ReadOnlySpan headerValueSpan = _headerValueRange == null ? _headerValueOctets.AsSpan(0, _headerValueLength) @@ -718,7 +718,7 @@ private void OnIndexedHeaderNamePostBase(int index) // _state = State.HeaderValueLength; } - private void OnPostBaseIndex(int intResult, IHttpHeadersHandler handler) + private void OnPostBaseIndex(int intResult, IHttpStreamHeadersHandler handler) { ThrowDynamicTableNotSupported(); // TODO @@ -743,7 +743,7 @@ private void OnRequiredInsertCount(int requiredInsertCount) _state = State.Base; } - private void OnIndexedHeaderField(int index, IHttpHeadersHandler handler) + private void OnIndexedHeaderField(int index, IHttpStreamHeadersHandler handler) { handler.OnStaticIndexedHeader(index); _state = State.CompressedHeaders; diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpHeadersHandler.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpHeadersHandler.cs deleted file mode 100644 index 96dfae364252c..0000000000000 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpHeadersHandler.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Don't ever change this unless we are explicitly trying to remove IHttpHeadersHandler as public API. -#if KESTREL -using System; - -namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http -#else -namespace System.Net.Http -#endif -{ -#if KESTREL - public -#else - internal -#endif - interface IHttpHeadersHandler - { - void OnStaticIndexedHeader(int index); - void OnStaticIndexedHeader(int index, ReadOnlySpan value); - void OnHeader(ReadOnlySpan name, ReadOnlySpan value); - void OnHeadersComplete(bool endStream); - - // DIM to avoid breaking change on public interface (for Kestrel). - public void OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) - { - OnHeader(name, value); - } - } -} diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpStreamHeadersHandler.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpStreamHeadersHandler.cs new file mode 100644 index 0000000000000..1d74d9d393c07 --- /dev/null +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/IHttpStreamHeadersHandler.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Net.Http +{ + internal interface IHttpStreamHeadersHandler + { + void OnStaticIndexedHeader(int index); + void OnStaticIndexedHeader(int index, ReadOnlySpan value); + void OnHeader(ReadOnlySpan name, ReadOnlySpan value); + void OnHeadersComplete(bool endStream); + void OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value); + } +} diff --git a/src/libraries/Common/tests/Common.Tests.csproj b/src/libraries/Common/tests/Common.Tests.csproj index 7273bddf88594..24841a2dedcf7 100644 --- a/src/libraries/Common/tests/Common.Tests.csproj +++ b/src/libraries/Common/tests/Common.Tests.csproj @@ -39,8 +39,8 @@ Link="Common\System\Net\HttpKnownHeaderNames.cs" /> - + DecodedHeaders { get; } = new Dictionary(); public Dictionary> DecodedStaticHeaders { get; } = new Dictionary>(); - void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) { string headerName = Encoding.ASCII.GetString(name); string headerValue = Encoding.ASCII.GetString(value); @@ -732,20 +732,28 @@ void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan va DecodedHeaders[headerName] = headerValue; } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index) { ref readonly HeaderField entry = ref H2StaticTable.Get(index - 1); - ((IHttpHeadersHandler)this).OnHeader(entry.Name, entry.Value); + ((IHttpStreamHeadersHandler)this).OnHeader(entry.Name, entry.Value); DecodedStaticHeaders[index] = new KeyValuePair(Encoding.ASCII.GetString(entry.Name), Encoding.ASCII.GetString(entry.Value)); } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) { byte[] name = H2StaticTable.Get(index - 1).Name; - ((IHttpHeadersHandler)this).OnHeader(name, value); + ((IHttpStreamHeadersHandler)this).OnHeader(name, value); DecodedStaticHeaders[index] = new KeyValuePair(Encoding.ASCII.GetString(name), Encoding.ASCII.GetString(value)); } - void IHttpHeadersHandler.OnHeadersComplete(bool endStream) { } + void IHttpStreamHeadersHandler.OnHeadersComplete(bool endStream) { } + + void IHttpStreamHeadersHandler.OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) + { + string headerName = Encoding.ASCII.GetString(name); + string headerValue = Encoding.ASCII.GetString(value); + + DecodedHeaders[headerName] = headerValue; + } } } diff --git a/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http3/QPackDecoderTest.cs b/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http3/QPackDecoderTest.cs index d9074fa06b05e..db79532693a13 100644 --- a/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http3/QPackDecoderTest.cs +++ b/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http3/QPackDecoderTest.cs @@ -264,12 +264,12 @@ private static void TestDecode(byte[] encoded, KeyValuePair[] ex } } - public class TestHttpHeadersHandler : IHttpHeadersHandler + public class TestHttpHeadersHandler : IHttpStreamHeadersHandler { public Dictionary DecodedHeaders { get; } = new Dictionary(); public Dictionary> DecodedStaticHeaders { get; } = new Dictionary>(); - void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) { if (name.Length == 0) { @@ -282,20 +282,28 @@ void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan va DecodedHeaders[headerName] = headerValue; } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index) { ref readonly HeaderField entry = ref H3StaticTable.Get(index); - ((IHttpHeadersHandler)this).OnHeader(entry.Name, entry.Value); + ((IHttpStreamHeadersHandler)this).OnHeader(entry.Name, entry.Value); DecodedStaticHeaders[index] = new KeyValuePair(Encoding.ASCII.GetString(entry.Name), Encoding.ASCII.GetString(entry.Value)); } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) { byte[] name = H3StaticTable.Get(index).Name; - ((IHttpHeadersHandler)this).OnHeader(name, value); + ((IHttpStreamHeadersHandler)this).OnHeader(name, value); DecodedStaticHeaders[index] = new KeyValuePair(Encoding.ASCII.GetString(name), Encoding.ASCII.GetString(value)); } - void IHttpHeadersHandler.OnHeadersComplete(bool endStream) { } + void IHttpStreamHeadersHandler.OnHeadersComplete(bool endStream) { } + + public void OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) + { + string headerName = Encoding.ASCII.GetString(name); + string headerValue = Encoding.ASCII.GetString(value); + + DecodedHeaders[headerName] = headerValue; + } } } diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index aba7097490c34..8b5076b5ca9e3 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -244,8 +244,8 @@ - - Common\System\Net\Http\aspnetcore\IHttpHeadersHandler.cs + + Common\System\Net\Http\aspnetcore\IHttpStreamHeadersHandler.cs Common\System\Net\Http\aspnetcore\Http2\Hpack\DynamicTable.cs diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs index 0f849d3d3aa3d..811d33dbfb4ef 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs @@ -603,7 +603,7 @@ private async ValueTask ProcessHeadersFrame(FrameHeader frameHeader) int streamId = frameHeader.StreamId; Http2Stream? http2Stream = GetStream(streamId); - IHttpHeadersHandler headersHandler; + IHttpStreamHeadersHandler headersHandler; if (http2Stream != null) { http2Stream.OnHeadersStart(); @@ -645,14 +645,15 @@ private async ValueTask ProcessHeadersFrame(FrameHeader frameHeader) http2Stream?.OnHeadersComplete(endStream); } - /// Nop implementation of used by . - private sealed class NopHeadersHandler : IHttpHeadersHandler + /// Nop implementation of used by . + private sealed class NopHeadersHandler : IHttpStreamHeadersHandler { public static readonly NopHeadersHandler Instance = new NopHeadersHandler(); - void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) { } - void IHttpHeadersHandler.OnHeadersComplete(bool endStream) { } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index) { } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) { } + void IHttpStreamHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) { } + void IHttpStreamHeadersHandler.OnHeadersComplete(bool endStream) { } + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index) { } + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) { } + void IHttpStreamHeadersHandler.OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) { } } private ReadOnlySpan GetFrameData(ReadOnlySpan frameData, bool hasPad, bool hasPriority) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs index 3f77cd7f88d61..6fc6f59a37033 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs @@ -18,7 +18,7 @@ namespace System.Net.Http { internal sealed partial class Http2Connection { - private sealed class Http2Stream : IValueTaskSource, IHttpHeadersHandler, IHttpTrace + private sealed class Http2Stream : IValueTaskSource, IHttpStreamHeadersHandler, IHttpTrace { private const int InitialStreamBufferSize = #if DEBUG @@ -525,7 +525,7 @@ public void OnWindowUpdate(int amount) (KnownHeaders.WWWAuthenticate.Descriptor, Array.Empty()), }; - void IHttpHeadersHandler.OnStaticIndexedHeader(int index) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index) { Debug.Assert(index >= FirstHPackRequestPseudoHeaderId && index <= LastHPackNormalHeaderId); @@ -548,7 +548,7 @@ void IHttpHeadersHandler.OnStaticIndexedHeader(int index) } } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) { Debug.Assert(index >= FirstHPackRequestPseudoHeaderId && index <= LastHPackNormalHeaderId); @@ -571,6 +571,11 @@ void IHttpHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan val } } + void IHttpStreamHeadersHandler.OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) + { + OnHeader(name, value); + } + private void AdjustHeaderBudget(int amount) { _headerBudgetRemaining -= amount; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs index 357e768e80319..3a236ccc65ae3 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs @@ -19,7 +19,7 @@ namespace System.Net.Http [SupportedOSPlatform("windows")] [SupportedOSPlatform("linux")] [SupportedOSPlatform("macos")] - internal sealed class Http3RequestStream : IHttpHeadersHandler, IAsyncDisposable, IDisposable + internal sealed class Http3RequestStream : IHttpStreamHeadersHandler, IAsyncDisposable, IDisposable { private readonly HttpRequestMessage _request; private Http3Connection _connection; @@ -859,7 +859,7 @@ private async ValueTask ReadHeadersAsync(long headersLength, CancellationToken c private static ReadOnlySpan StatusHeaderNameBytes => new byte[] { (byte)'s', (byte)'t', (byte)'a', (byte)'t', (byte)'u', (byte)'s' }; - void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan value) { Debug.Assert(name.Length > 0); if (!HeaderDescriptor.TryGet(name, out HeaderDescriptor descriptor)) @@ -870,18 +870,23 @@ void IHttpHeadersHandler.OnHeader(ReadOnlySpan name, ReadOnlySpan va OnHeader(staticIndex: null, descriptor, staticValue: default, literalValue: value); } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index) { GetStaticQPackHeader(index, out HeaderDescriptor descriptor, out string? knownValue); OnHeader(index, descriptor, knownValue, literalValue: default); } - void IHttpHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) + void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan value) { GetStaticQPackHeader(index, out HeaderDescriptor descriptor, knownValue: out _); OnHeader(index, descriptor, staticValue: null, literalValue: value); } + void IHttpStreamHeadersHandler.OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) + { + ((IHttpStreamHeadersHandler)this).OnHeader(name, value); + } + private void GetStaticQPackHeader(int index, out HeaderDescriptor descriptor, out string? knownValue) { if (!HeaderDescriptor.TryGetStaticQPackHeader(index, out descriptor, out knownValue)) @@ -1017,7 +1022,7 @@ int ParseStatusCode(int? index, string value) } } - void IHttpHeadersHandler.OnHeadersComplete(bool endStream) + void IHttpStreamHeadersHandler.OnHeadersComplete(bool endStream) { Debug.Fail($"This has no use in HTTP/3 and should never be called by {nameof(QPackDecoder)}."); } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/HPack/HPackRoundtripTests.cs b/src/libraries/System.Net.Http/tests/UnitTests/HPack/HPackRoundtripTests.cs index 7ddee86b7f125..c3b16afb47360 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/HPack/HPackRoundtripTests.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/HPack/HPackRoundtripTests.cs @@ -147,7 +147,7 @@ private static HttpHeaders HPackDecode(Memory memory, Encoding? valueEncod return header; } - private class HeaderHandler : IHttpHeadersHandler + private class HeaderHandler : IHttpStreamHeadersHandler { HttpRequestHeaders _headers; Encoding? _valueEncoding; @@ -185,6 +185,11 @@ public void OnStaticIndexedHeader(int index, ReadOnlySpan value) { OnHeader(H2StaticTable.Get(index - 1).Name, value); } + + public void OnDynamicIndexedHeader(int? index, ReadOnlySpan name, ReadOnlySpan value) + { + OnHeader(name, value); + } } } } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj index 0a92e47df32ea..801ad4c057274 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj @@ -351,8 +351,8 @@ Link="ProductionCode\Common\Interop\Windows\WinHttp\Interop.winhttp_types.cs" /> - +