@@ -851,7 +851,7 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
851
851
queryString = begin . GetAsciiString ( scan ) ;
852
852
}
853
853
854
- var rawTarget = pathBegin . GetAsciiString ( scan ) ;
854
+ var queryEnd = scan ;
855
855
856
856
if ( pathBegin . Peek ( ) == ' ' )
857
857
{
@@ -900,8 +900,12 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
900
900
// Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8;
901
901
// then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs"
902
902
string requestUrlPath ;
903
+ string rawTarget ;
903
904
if ( needDecode )
904
905
{
906
+ // Read raw target before mutating memory.
907
+ rawTarget = pathBegin . GetAsciiString ( queryEnd ) ;
908
+
905
909
// URI was encoded, unescape and then parse as utf8
906
910
pathEnd = UrlPathDecoder . Unescape ( pathBegin , pathEnd ) ;
907
911
requestUrlPath = pathBegin . GetUtf8String ( pathEnd ) ;
@@ -911,6 +915,17 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
911
915
{
912
916
// URI wasn't encoded, parse as ASCII
913
917
requestUrlPath = pathBegin . GetAsciiString ( pathEnd ) ;
918
+
919
+ if ( queryString . Length == 0 )
920
+ {
921
+ // No need to allocate an extra string if the path didn't need
922
+ // decoding and there's no query string following it.
923
+ rawTarget = requestUrlPath ;
924
+ }
925
+ else
926
+ {
927
+ rawTarget = pathBegin . GetAsciiString ( queryEnd ) ;
928
+ }
914
929
}
915
930
916
931
requestUrlPath = PathNormalizer . RemoveDotSegments ( requestUrlPath ) ;
0 commit comments