diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs index 463ce0a237..bc6757b30e 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/Frame.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Pipelines; -using System.IO.Pipelines.Text.Primitives; using System.Linq; using System.Net; using System.Runtime.CompilerServices; @@ -1232,7 +1231,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http // URI was encoded, unescape and then parse as utf8 int pathLength = UrlEncoder.Decode(path, path); - requestUrlPath = new Utf8String(path.Slice(0, pathLength)).ToString(); + requestUrlPath = GetUtf8String(path.Slice(0, pathLength)); } else { @@ -1282,6 +1281,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http } } + private unsafe static string GetUtf8String(Span path) + { + // .NET 451 doesn't have pointer overloads for Encoding.GetString so we + // copy to an array +#if NET451 + return Encoding.UTF8.GetString(path.ToArray()); +#else + fixed (byte* pointer = &path.DangerousGetPinnableReference()) + { + return Encoding.UTF8.GetString(pointer, path.Length); + } +#endif + } + public void OnHeader(Span name, Span value) { _requestHeadersParsed++; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj index 35ccda46b3..beacc7f230 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -19,7 +19,6 @@ -