diff --git a/SimpleHttpServer/HttpServer.cs b/SimpleHttpServer/HttpServer.cs index 43634d5..0ce8ecc 100644 --- a/SimpleHttpServer/HttpServer.cs +++ b/SimpleHttpServer/HttpServer.cs @@ -118,25 +118,27 @@ public sealed class HttpServer { } foreach (var location in attrib.Locations) { - int idx = location.IndexOf('{'); + var normLocation = NormalizeUrlPath(location); + int idx = normLocation.IndexOf('{'); if (idx >= 0) { // this path contains path parameters throw new NotImplementedException("Path parameters are not yet implemented!"); } var reqMethod = Enum.GetName(attrib.RequestMethod) ?? throw new ArgumentException("Request method was undefined"); - simpleEndpointMethodInfos.Add((location, reqMethod), new EndpointInvocationInfo(mi, qparams)); + simpleEndpointMethodInfos.Add((normLocation, reqMethod), new EndpointInvocationInfo(mi, qparams)); } } } private readonly Dictionary stringToTypeParameterConverters = new(); + private string NormalizeUrlPath(string url) => '/' + url.TrimStart('/'); private async Task ProcessRequestAsync(HttpListenerContext ctx) { try { var decUri = WebUtility.UrlDecode(ctx.Request.RawUrl)!; // TODO add path escape countermeasures+unittests - var splitted = decUri.Split('?', 2, StringSplitOptions.None); + var splitted = NormalizeUrlPath(decUri).Split('?', 2, StringSplitOptions.None); var path = WebUtility.UrlDecode(splitted.First());