improve TryGetHandler to find direct matches before checking via RegEx
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user