Skip to content

Commit

Permalink
Improve path search in Kestrel parsing (#51535)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Nov 9, 2023
1 parent 099783a commit 6699b05
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,19 @@ private void ParseRequestLine(TRequestHandler handler, ReadOnlySpan<byte> reques
offset++;

// Find end of path and if path is encoded
for (; (uint)offset < (uint)requestLine.Length; offset++)
var index = requestLine.Slice(offset).IndexOfAny(ByteSpace, ByteQuestionMark, BytePercentage);
if (index >= 0)
{
ch = requestLine[offset];
if (ch == ByteSpace || ch == ByteQuestionMark)
{
// End of path
break;
}
else if (ch == BytePercentage)
if (requestLine[offset + index] == BytePercentage)
{
pathEncoded = true;
offset += index;
// Found an encoded character, now just search for end of path
index = requestLine.Slice(offset).IndexOfAny(ByteSpace, ByteQuestionMark);
}

offset += index;
ch = requestLine[offset];
}

var path = new TargetOffsetPathLength(targetStart, length: offset - targetStart, pathEncoded);
Expand Down

0 comments on commit 6699b05

Please sign in to comment.