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)
|
protected virtual bool TryGetHandler(string url, string? query, string method, [NotNullWhen(true)] out PrivateMessageHandler? handler)
|
||||||
{
|
{
|
||||||
handler = handlers.FirstOrDefault(handler =>
|
// Filter by method
|
||||||
{
|
var filtered = handlers.Where(handler => handler.Attribute.Methods.Contains(method));
|
||||||
if (!handler.Attribute.Methods.Contains(method))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (handler.UseRegEx)
|
// Check if equals via string comparation (ignore-case)
|
||||||
return Regex.IsMatch(url, handler.Url, RegexOptions.IgnoreCase);
|
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;
|
return handler != null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user