Shrink ParseRequestLine inner loop (#6594)
This commit is contained in:
parent
c7f05c614a
commit
b27739ad3f
|
|
@ -73,62 +73,51 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
|||
private unsafe void ParseRequestLine(TRequestHandler handler, byte* data, int length)
|
||||
{
|
||||
// Get Method and set the offset
|
||||
var method = HttpUtilities.GetKnownMethod(data, length, out var offset);
|
||||
var method = HttpUtilities.GetKnownMethod(data, length, out var pathStartOffset);
|
||||
|
||||
Span<byte> customMethod = method == HttpMethod.Custom ?
|
||||
GetUnknownMethod(data, length, out offset) :
|
||||
default;
|
||||
Span<byte> customMethod = default;
|
||||
if (method == HttpMethod.Custom)
|
||||
{
|
||||
customMethod = GetUnknownMethod(data, length, out pathStartOffset);
|
||||
}
|
||||
|
||||
// Use a new offset var as pathStartOffset needs to be on stack
|
||||
// as its passed by reference above so can't be in register.
|
||||
// Skip space
|
||||
offset++;
|
||||
var offset = pathStartOffset + 1;
|
||||
if (offset >= length)
|
||||
{
|
||||
// Start of path not found
|
||||
RejectRequestLine(data, length);
|
||||
}
|
||||
|
||||
byte ch = data[offset];
|
||||
if (ch == ByteSpace || ch == ByteQuestionMark || ch == BytePercentage)
|
||||
{
|
||||
// Empty path is illegal, or path starting with percentage
|
||||
RejectRequestLine(data, length);
|
||||
}
|
||||
|
||||
byte ch = 0;
|
||||
// Target = Path and Query
|
||||
var pathEncoded = false;
|
||||
var pathStart = -1;
|
||||
var pathStart = offset;
|
||||
|
||||
// Skip first char (just checked)
|
||||
offset++;
|
||||
|
||||
// Find end of path and if path is encoded
|
||||
for (; offset < length; offset++)
|
||||
{
|
||||
ch = data[offset];
|
||||
if (ch == ByteSpace)
|
||||
if (ch == ByteSpace || ch == ByteQuestionMark)
|
||||
{
|
||||
if (pathStart == -1)
|
||||
{
|
||||
// Empty path is illegal
|
||||
RejectRequestLine(data, length);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (ch == ByteQuestionMark)
|
||||
{
|
||||
if (pathStart == -1)
|
||||
{
|
||||
// Empty path is illegal
|
||||
RejectRequestLine(data, length);
|
||||
}
|
||||
|
||||
// End of path
|
||||
break;
|
||||
}
|
||||
else if (ch == BytePercentage)
|
||||
{
|
||||
if (pathStart == -1)
|
||||
{
|
||||
// Path starting with % is illegal
|
||||
RejectRequestLine(data, length);
|
||||
}
|
||||
|
||||
pathEncoded = true;
|
||||
}
|
||||
else if (pathStart == -1)
|
||||
{
|
||||
pathStart = offset;
|
||||
}
|
||||
}
|
||||
|
||||
if (pathStart == -1)
|
||||
{
|
||||
// Start of path not found
|
||||
RejectRequestLine(data, length);
|
||||
}
|
||||
|
||||
var pathBuffer = new Span<byte>(data + pathStart, offset - pathStart);
|
||||
|
|
|
|||
Loading…
Reference in New Issue