diff --git a/Pilz.Net/Api/ApiServer.cs b/Pilz.Net/Api/ApiServer.cs index b15979b..0807e04 100644 --- a/Pilz.Net/Api/ApiServer.cs +++ b/Pilz.Net/Api/ApiServer.cs @@ -408,16 +408,14 @@ public class ApiServer(string apiUrl) : IApiServer protected virtual bool TryGetHandler(string url, string? query, string method, [NotNullWhen(true)] out PrivateMessageHandler? handler) { - handler = handlers.FirstOrDefault(handler => - { - if (!handler.Attribute.Methods.Contains(method)) - return false; + // Filter by method + var filtered = handlers.Where(handler => handler.Attribute.Methods.Contains(method)); - if (handler.UseRegEx) - return Regex.IsMatch(url, handler.Url, RegexOptions.IgnoreCase); + // Check if equals via string comparation (ignore-case) + handler = filtered.FirstOrDefault(handler => handler.Url.Equals(url, StringComparison.InvariantCultureIgnoreCase)); - return handler.Url.Equals(url, StringComparison.InvariantCultureIgnoreCase); - }); + // Check if equals via RegEx + handler ??= filtered.Where(n => n.UseRegEx).FirstOrDefault(handler => handler.Url.Equals(url, StringComparison.InvariantCultureIgnoreCase)); return handler != null; }