feat: add rate limiting and startup options validation

This commit is contained in:
xiong
2026-07-26 13:46:17 +08:00
parent f4783c5de3
commit 015c9b5582
9 changed files with 204 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
namespace Tiku.Api.Options;
public static class OptionsValidation
{
public static bool BeValidCorsOptions(CorsOptions options)
{
if (options.AllowCredentials && options.AllowedOrigins.Length == 0)
{
return false;
}
return options.AllowedOrigins.All(IsHttpOrigin);
}
private static bool IsHttpOrigin(string origin)
{
return Uri.TryCreate(origin, UriKind.Absolute, out var uri) &&
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) &&
string.IsNullOrEmpty(uri.PathAndQuery.Trim('/'));
}
}