Reuse Http2MessageBody (#19629)
This commit is contained in:
parent
8ad0f1fbe6
commit
88b134f877
|
|
@ -16,8 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
protected readonly Http1Connection _context;
|
protected readonly Http1Connection _context;
|
||||||
protected bool _completed;
|
protected bool _completed;
|
||||||
|
|
||||||
protected Http1MessageBody(Http1Connection context)
|
protected Http1MessageBody(Http1Connection context) : base(context)
|
||||||
: base(context)
|
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
|
|
||||||
protected virtual Task OnStopAsync() => Task.CompletedTask;
|
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()
|
protected void TryProduceContinue()
|
||||||
{
|
{
|
||||||
if (_send100Continue)
|
if (_send100Continue)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
private readonly Http2Stream _context;
|
private readonly Http2Stream _context;
|
||||||
private ReadResult _readResult;
|
private ReadResult _readResult;
|
||||||
|
|
||||||
private Http2MessageBody(Http2Stream context)
|
public Http2MessageBody(Http2Stream context)
|
||||||
: base(context)
|
: base(context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
|
@ -46,14 +46,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
AddAndCheckConsumedBytes(bytesRead);
|
AddAndCheckConsumedBytes(bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageBody For(Http2Stream context)
|
public override void Reset()
|
||||||
{
|
{
|
||||||
if (context.ReceivedEmptyRequestBody)
|
base.Reset();
|
||||||
{
|
_readResult = default;
|
||||||
return ZeroContentLengthClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Http2MessageBody(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AdvanceTo(SequencePosition consumed)
|
public override void AdvanceTo(SequencePosition consumed)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
private Http2OutputProducer _http2Output;
|
private Http2OutputProducer _http2Output;
|
||||||
private StreamInputFlowControl _inputFlowControl;
|
private StreamInputFlowControl _inputFlowControl;
|
||||||
private StreamOutputFlowControl _outputFlowControl;
|
private StreamOutputFlowControl _outputFlowControl;
|
||||||
|
private Http2MessageBody _messageBody;
|
||||||
|
|
||||||
private bool _decrementCalled;
|
private bool _decrementCalled;
|
||||||
|
|
||||||
|
|
@ -170,7 +171,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
=> StringUtilities.ConcatAsHexSuffix(ConnectionId, ':', (uint)StreamId);
|
=> StringUtilities.ConcatAsHexSuffix(ConnectionId, ':', (uint)StreamId);
|
||||||
|
|
||||||
protected override MessageBody CreateMessageBody()
|
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
|
// Compare to Http1Connection.OnStartLine
|
||||||
protected override bool TryParseRequest(ReadResult result, out bool endConnection)
|
protected override bool TryParseRequest(ReadResult result, out bool endConnection)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue