Reuse Http2MessageBody (#19629)

This commit is contained in:
James Newton-King 2020-03-12 09:38:29 +13:00 committed by GitHub
parent 8ad0f1fbe6
commit 88b134f877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 11 deletions

View File

@ -16,8 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
protected readonly Http1Connection _context;
protected bool _completed;
protected Http1MessageBody(Http1Connection context)
: base(context)
protected Http1MessageBody(Http1Connection context) : base(context)
{
_context = context;
}

View File

@ -73,6 +73,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
protected virtual Task OnStopAsync() => Task.CompletedTask;
public virtual void Reset()
{
_send100Continue = true;
_consumedBytes = 0;
_stopped = false;
_timingEnabled = false;
_backpressure = false;
_alreadyTimedBytes = 0;
_examinedUnconsumedBytes = 0;
}
protected void TryProduceContinue()
{
if (_send100Continue)

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
private readonly Http2Stream _context;
private ReadResult _readResult;
private Http2MessageBody(Http2Stream context)
public Http2MessageBody(Http2Stream context)
: base(context)
{
_context = context;
@ -46,14 +46,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
AddAndCheckConsumedBytes(bytesRead);
}
public static MessageBody For(Http2Stream context)
public override void Reset()
{
if (context.ReceivedEmptyRequestBody)
{
return ZeroContentLengthClose;
}
return new Http2MessageBody(context);
base.Reset();
_readResult = default;
}
public override void AdvanceTo(SequencePosition consumed)

View File

@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
private Http2OutputProducer _http2Output;
private StreamInputFlowControl _inputFlowControl;
private StreamOutputFlowControl _outputFlowControl;
private Http2MessageBody _messageBody;
private bool _decrementCalled;
@ -170,7 +171,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
=> StringUtilities.ConcatAsHexSuffix(ConnectionId, ':', (uint)StreamId);
protected override MessageBody CreateMessageBody()
=> Http2MessageBody.For(this);
{
if (ReceivedEmptyRequestBody)
{
return MessageBody.ZeroContentLengthClose;
}
if (_messageBody != null)
{
_messageBody.Reset();
}
else
{
_messageBody = new Http2MessageBody(this);
}
return _messageBody;
}
// Compare to Http1Connection.OnStartLine
protected override bool TryParseRequest(ReadResult result, out bool endConnection)