Add option to ignore trailing slashes in requests

This commit is contained in:
GHXX committed 2025-06-02 17:23:35 +02:00
1 parent 6ad805841d
commit d2a3a82b95
2 files changed
+11 -2

No files matched your search

+7 -2
View File
@@ -213,7 +213,7 @@ public sealed class HttpServer {
private readonly Dictionary<Type, IParameterConverter> stringToTypeParameterConverters = new();
private static string NormalizeUrlPath(string url) {
private string NormalizeUrlPath(string url) {
var fwdSlashUrl = url.Replace('\\', '/');
var segments = fwdSlashUrl.Trim('/').Split('/', StringSplitOptions.RemoveEmptyEntries).ToList();
@@ -242,7 +242,12 @@ public sealed class HttpServer {
}
rv.AppendJoin('/', simplifiedSegmentsReversed.Reverse<string>());
return '/' + (rv.ToString().TrimEnd('/') + (fwdSlashUrl.EndsWith('/') ? "/" : "")).TrimStart('/');
var suffix = (rv.ToString().TrimEnd('/') + (fwdSlashUrl.EndsWith('/') ? "/" : "")).TrimStart('/');
if (conf.TrimTrailingSlash) {
suffix = suffix.TrimEnd('/');
}
return '/' + suffix;
}
private async Task ProcessRequestAsync(HttpListenerContext ctx) {