Fix reading DATA frames with maximum length.
This commit is contained in:
parent
c8f9364e3e
commit
9944c0fd43
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<byte> Raw => new ArraySegment<byte>(_data, 0, HeaderLength + Length);
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue