aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-01-14 18:46:10 -0600
committerJP Dillingham <jp@dillingham.me>2026-01-14 18:46:10 -0600
commitd7b59050ecc39448c34741552fb489f88457e346 (patch)
treeda0b88e10d774d602d46b48193d36944e4db2baf /src
parent9eed9ca110e78f08c885d33795272c3aad3f133f (diff)
downloadslskd-d7b59050ecc39448c34741552fb489f88457e346.tar.gz
rearrange model binder
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Middleware/UrlEncodingModelBinder.cs23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/slskd/Common/Middleware/UrlEncodingModelBinder.cs b/src/slskd/Common/Middleware/UrlEncodingModelBinder.cs
index 6729b374..27ea3258 100644
--- a/src/slskd/Common/Middleware/UrlEncodingModelBinder.cs
+++ b/src/slskd/Common/Middleware/UrlEncodingModelBinder.cs
@@ -63,8 +63,18 @@ public class UrlEncodingModelBinder : IModelBinder
*/
try
{
+ var request = bindingContext.HttpContext.Request;
+
var model = $"{{{bindingContext.ModelName}}}";
var template = bindingContext.ActionContext.ActionDescriptor.AttributeRouteInfo?.Template ?? string.Empty;
+
+ // if the application is running with a base path (e.g., /slskd), we need to add it to the template
+ // as it isn't included out of the box
+ if (request.PathBase.HasValue)
+ {
+ template = $"{request.PathBase.Value.Trim('/')}/{template}";
+ }
+
var index = template
.Split('/', StringSplitOptions.RemoveEmptyEntries)
.Select((segment, index) => new { Segment = segment, Index = index })
@@ -75,18 +85,7 @@ public class UrlEncodingModelBinder : IModelBinder
// a value that's already had one pass of url decoding applied
var rawUrl = bindingContext.HttpContext.Features.Get<IHttpRequestFeature>()?.RawTarget ?? string.Empty;
- var request = bindingContext.HttpContext.Request;
- var absolutePath = new Uri($"{request.Scheme}://{request.Host}{rawUrl}").AbsolutePath; // discard query string
-
- // if the application is running with a base path (e.g., /slskd), we need to remove it
- // from the absolute path before splitting, as the route template doesn't include it
- var pathBase = request.PathBase.Value ?? string.Empty;
- if (!string.IsNullOrEmpty(pathBase) && absolutePath.StartsWith(pathBase, StringComparison.OrdinalIgnoreCase))
- {
- absolutePath = absolutePath.Substring(pathBase.Length);
- }
-
- var rawValue = absolutePath
+ var rawValue = new Uri($"{request.Scheme}://{request.Host}{rawUrl}").AbsolutePath // discard query string
.Split('/', StringSplitOptions.RemoveEmptyEntries)
.ElementAtOrDefault(index);