Skip to content

Commit 6699b05

Browse files
Improve path search in Kestrel parsing (#51535)
1 parent 099783a commit 6699b05

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,19 @@ private void ParseRequestLine(TRequestHandler handler, ReadOnlySpan<byte> reques
105105
offset++;
106106

107107
// Find end of path and if path is encoded
108-
for (; (uint)offset < (uint)requestLine.Length; offset++)
108+
var index = requestLine.Slice(offset).IndexOfAny(ByteSpace, ByteQuestionMark, BytePercentage);
109+
if (index >= 0)
109110
{
110-
ch = requestLine[offset];
111-
if (ch == ByteSpace || ch == ByteQuestionMark)
112-
{
113-
// End of path
114-
break;
115-
}
116-
else if (ch == BytePercentage)
111+
if (requestLine[offset + index] == BytePercentage)
117112
{
118113
pathEncoded = true;
114+
offset += index;
115+
// Found an encoded character, now just search for end of path
116+
index = requestLine.Slice(offset).IndexOfAny(ByteSpace, ByteQuestionMark);
119117
}
118+
119+
offset += index;
120+
ch = requestLine[offset];
120121
}
121122

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

0 commit comments

Comments
 (0)