Perf: Remove unnecessary path checks
This commit is contained in:
parent
bcdd3147a1
commit
6224f5b6e8
|
|
@ -919,7 +919,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
// URI was encoded, unescape and then parse as utf8
|
// URI was encoded, unescape and then parse as utf8
|
||||||
pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd);
|
pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd);
|
||||||
requestUrlPath = pathBegin.GetUtf8String(pathEnd);
|
requestUrlPath = pathBegin.GetUtf8String(pathEnd);
|
||||||
requestUrlPath = PathNormalizer.NormalizeToNFC(requestUrlPath);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
public static class PathNormalizer
|
public static class PathNormalizer
|
||||||
{
|
{
|
||||||
public static string NormalizeToNFC(string path)
|
|
||||||
{
|
|
||||||
if (!path.IsNormalized(NormalizationForm.FormC))
|
|
||||||
{
|
|
||||||
path = path.Normalize(NormalizationForm.FormC);
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RemoveDotSegments(string path)
|
public static string RemoveDotSegments(string path)
|
||||||
{
|
{
|
||||||
if (ContainsDotSegments(path))
|
if (ContainsDotSegments(path))
|
||||||
|
|
|
||||||
|
|
@ -156,8 +156,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel
|
||||||
serverAddress.PathBase = url.Substring(pathDelimiterEnd);
|
serverAddress.PathBase = url.Substring(pathDelimiterEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
serverAddress.PathBase = PathNormalizer.NormalizeToNFC(serverAddress.PathBase);
|
|
||||||
|
|
||||||
return serverAddress;
|
return serverAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,5 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var result = PathNormalizer.RemoveDotSegments(input);
|
var result = PathNormalizer.RemoveDotSegments(input);
|
||||||
Assert.Equal(expected, result);
|
Assert.Equal(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void NormalizesToNFC()
|
|
||||||
{
|
|
||||||
var result = PathNormalizer.NormalizeToNFC("/\u0041\u030A");
|
|
||||||
Assert.True(result.IsNormalized(NormalizationForm.FormC));
|
|
||||||
Assert.Equal("/\u00C5", result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
Assert.Equal("/\u00C5", context.Request.PathBase.Value);
|
Assert.Equal("/A", context.Request.PathBase.Value);
|
||||||
Assert.Equal("/B/\u00C5", context.Request.Path.Value);
|
Assert.Equal("/B/C", context.Request.Path.Value);
|
||||||
|
|
||||||
context.Response.Headers["Content-Length"] = new[] { "11" };
|
context.Response.Headers["Content-Length"] = new[] { "11" };
|
||||||
await context.Response.WriteAsync("Hello World");
|
await context.Response.WriteAsync("Hello World");
|
||||||
}, testContext, "http://127.0.0.1:0/\u0041\u030A"))
|
}, testContext, "http://127.0.0.1:0/A"))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var connection = server.CreateConnection())
|
||||||
{
|
{
|
||||||
await connection.SendEnd(
|
await connection.SendEnd(
|
||||||
"GET /%41%CC%8A/A/../B/%41%CC%8A HTTP/1.0",
|
"GET /A/0/../B/C HTTP/1.0",
|
||||||
"",
|
"",
|
||||||
"");
|
"");
|
||||||
await connection.ReceiveEnd(
|
await connection.ReceiveEnd(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
using Microsoft.AspNetCore.Server.Kestrel;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -68,15 +67,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
Assert.Equal(toString ?? url, serverAddress.ToString());
|
Assert.Equal(toString ?? url, serverAddress.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void PathBaseIsNormalized()
|
|
||||||
{
|
|
||||||
var serverAddres = ServerAddress.FromUrl("http://localhost:8080/p\u0041\u030Athbase");
|
|
||||||
|
|
||||||
Assert.True(serverAddres.PathBase.IsNormalized(NormalizationForm.FormC));
|
|
||||||
Assert.Equal("/p\u00C5thbase", serverAddres.PathBase);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithHostReturnsNewInstanceWithDifferentHost()
|
public void WithHostReturnsNewInstanceWithDifferentHost()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue