diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs index 78adb78c57..9a0760fe6e 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.Data.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 { var padded = padLength != null; - Length = MinAllowedMaxFrameSize - HeaderLength; + Length = MinAllowedMaxFrameSize; Type = Http2FrameType.DATA; DataFlags = padded ? Http2DataFrameFlags.PADDED : Http2DataFrameFlags.NONE; StreamId = streamId; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs index 3e9e15750d..e0dbf8bd09 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Frame.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Frame.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private const int StreamIdOffset = 5; private const int PayloadOffset = 9; - private readonly byte[] _data = new byte[MinAllowedMaxFrameSize]; + private readonly byte[] _data = new byte[HeaderLength + MinAllowedMaxFrameSize]; public ArraySegment Raw => new ArraySegment(_data, 0, HeaderLength + Length); diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 1a193e02b3..56f2787b83 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -71,6 +71,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private static readonly byte[] _worldBytes = Encoding.ASCII.GetBytes("world"); private static readonly byte[] _helloWorldBytes = Encoding.ASCII.GetBytes("hello, world"); private static readonly byte[] _noData = new byte[0]; + private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Frame.MinAllowedMaxFrameSize)); private readonly PipeFactory _pipeFactory = new PipeFactory(); private readonly (IPipeConnection Transport, IPipeConnection Application) _pair; @@ -248,6 +249,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(dataFrame.DataPayload, _helloWorldBytes); } + [Fact] + public async Task DATA_Received_MaxSize_ReadByStream() + { + await InitializeConnectionAsync(_echoApplication); + + await StartStreamAsync(1, _browserRequestHeaders, endStream: false); + await SendDataAsync(1, _maxData, endStream: true); + + await ExpectAsync(Http2FrameType.HEADERS, + withLength: 37, + withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS, + withStreamId: 1); + var dataFrame = await ExpectAsync(Http2FrameType.DATA, + withLength: _maxData.Length, + withFlags: (byte)Http2DataFrameFlags.NONE, + withStreamId: 1); + await ExpectAsync(Http2FrameType.DATA, + withLength: 0, + withFlags: (byte)Http2DataFrameFlags.END_STREAM, + withStreamId: 1); + + await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); + + Assert.Equal(dataFrame.DataPayload, _maxData); + } + [Fact] public async Task DATA_Received_Multiple_ReadByStream() {