parent
fff3e1ebd0
commit
30010a103b
|
|
@ -413,15 +413,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
protected override MessageBody CreateMessageBody()
|
protected override MessageBody CreateMessageBody()
|
||||||
=> Http1MessageBody.For(_httpVersion, HttpRequestHeaders, this);
|
=> Http1MessageBody.For(_httpVersion, HttpRequestHeaders, this);
|
||||||
|
|
||||||
protected override async Task<bool> ParseRequestAsync()
|
protected override void BeginRequestProcessing()
|
||||||
{
|
{
|
||||||
|
// Reset the features and timeout.
|
||||||
Reset();
|
Reset();
|
||||||
TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.StopProcessingNextRequest);
|
TimeoutControl.SetTimeout(_keepAliveTicks, TimeoutAction.StopProcessingNextRequest);
|
||||||
|
}
|
||||||
|
|
||||||
while (_requestProcessingStatus != RequestProcessingStatus.AppStarted)
|
protected override bool BeginRead(out ReadableBufferAwaitable awaitable)
|
||||||
{
|
{
|
||||||
var result = await Input.ReadAsync();
|
awaitable = Input.ReadAsync();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool TryParseRequest(ReadResult result, out bool endConnection)
|
||||||
|
{
|
||||||
var examined = result.Buffer.End;
|
var examined = result.Buffer.End;
|
||||||
var consumed = result.Buffer.End;
|
var consumed = result.Buffer.End;
|
||||||
|
|
||||||
|
|
@ -448,7 +454,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
switch (_requestProcessingStatus)
|
switch (_requestProcessingStatus)
|
||||||
{
|
{
|
||||||
case RequestProcessingStatus.RequestPending:
|
case RequestProcessingStatus.RequestPending:
|
||||||
return false;
|
endConnection = true;
|
||||||
|
return true;
|
||||||
case RequestProcessingStatus.ParsingRequestLine:
|
case RequestProcessingStatus.ParsingRequestLine:
|
||||||
throw BadHttpRequestException.GetException(
|
throw BadHttpRequestException.GetException(
|
||||||
RequestRejectionReason.InvalidRequestLine);
|
RequestRejectionReason.InvalidRequestLine);
|
||||||
|
|
@ -461,7 +468,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
{
|
{
|
||||||
// Stop the request processing loop if the server is shutting down or there was a keep-alive timeout
|
// Stop the request processing loop if the server is shutting down or there was a keep-alive timeout
|
||||||
// and there is no ongoing request.
|
// and there is no ongoing request.
|
||||||
return false;
|
endConnection = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if (RequestTimedOut)
|
else if (RequestTimedOut)
|
||||||
{
|
{
|
||||||
|
|
@ -469,11 +477,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
// a 408 response.
|
// a 408 response.
|
||||||
throw BadHttpRequestException.GetException(RequestRejectionReason.RequestTimeout);
|
throw BadHttpRequestException.GetException(RequestRejectionReason.RequestTimeout);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
endConnection = false;
|
||||||
|
if (_requestProcessingStatus == RequestProcessingStatus.AppStarted)
|
||||||
|
{
|
||||||
EnsureHostHeaderExists();
|
EnsureHostHeaderExists();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -375,11 +375,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void BeginRequestProcessing()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual bool BeginRead(out ReadableBufferAwaitable awaitable)
|
||||||
|
{
|
||||||
|
awaitable = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract string CreateRequestId();
|
protected abstract string CreateRequestId();
|
||||||
|
|
||||||
protected abstract MessageBody CreateMessageBody();
|
protected abstract MessageBody CreateMessageBody();
|
||||||
|
|
||||||
protected abstract Task<bool> ParseRequestAsync();
|
protected abstract bool TryParseRequest(ReadResult result, out bool endConnection);
|
||||||
|
|
||||||
protected abstract void CreateHttpContext();
|
protected abstract void CreateHttpContext();
|
||||||
|
|
||||||
|
|
@ -436,7 +446,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
{
|
{
|
||||||
while (_keepAlive)
|
while (_keepAlive)
|
||||||
{
|
{
|
||||||
if (!await ParseRequestAsync())
|
BeginRequestProcessing();
|
||||||
|
|
||||||
|
var result = default(ReadResult);
|
||||||
|
var endConnection = false;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (BeginRead(out var awaitable))
|
||||||
|
{
|
||||||
|
result = await awaitable;
|
||||||
|
}
|
||||||
|
} while (!TryParseRequest(result, out endConnection));
|
||||||
|
|
||||||
|
if (endConnection)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
protected override MessageBody CreateMessageBody()
|
protected override MessageBody CreateMessageBody()
|
||||||
=> Http2MessageBody.For(HttpRequestHeaders, this);
|
=> Http2MessageBody.For(HttpRequestHeaders, this);
|
||||||
|
|
||||||
protected override Task<bool> ParseRequestAsync()
|
protected override bool TryParseRequest(ReadResult result, out bool endConnection)
|
||||||
{
|
{
|
||||||
|
// We don't need any of the parameters because we don't implement BeginRead to actually
|
||||||
|
// do the reading from a pipeline, nor do we use endConnection to report connection-level errors.
|
||||||
|
|
||||||
Method = RequestHeaders[":method"];
|
Method = RequestHeaders[":method"];
|
||||||
Scheme = RequestHeaders[":scheme"];
|
Scheme = RequestHeaders[":scheme"];
|
||||||
_httpVersion = Http.HttpVersion.Http2;
|
_httpVersion = Http.HttpVersion.Http2;
|
||||||
|
|
@ -62,7 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
|
|
||||||
RequestHeaders["Host"] = RequestHeaders[":authority"];
|
RequestHeaders["Host"] = RequestHeaders[":authority"];
|
||||||
|
|
||||||
return Task.FromResult(true);
|
endConnection = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnDataAsync(ArraySegment<byte> data, bool endStream)
|
public async Task OnDataAsync(ArraySegment<byte> data, bool endStream)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue