taolib.testing.rate_limiter.limiter#
Rate Limiter core engine.
Implements the sliding window rate limiting logic with whitelist support and path-specific rules.
Classes#
限流引擎核心类。 |
Module Contents#
- class taolib.testing.rate_limiter.limiter.RateLimiter(config: taolib.testing.rate_limiter.config.RateLimitConfig, store: taolib.testing.rate_limiter.store.RateLimitStoreProtocol)#
限流引擎核心类。
负责: - 白名单检查 - 路径规则匹配 - 滑动窗口计数 - 限流决策
- 参数:
config -- 限流配置
store -- 存储后端(Redis 或内存)
- _config#
- _store#
- _get_rule_for_path(path: str, method: str) tuple[int, int]#
获取路径对应的限流规则。
- 参数:
path -- 请求路径
method -- HTTP 方法
- 返回:
(limit, window_seconds) 元组
- async check_limit(identifier: str, path: str, method: str = 'GET') taolib.testing.rate_limiter.models.RateLimitResult#
检查请求是否超出限流阈值。
- 参数:
identifier -- 用户标识符(如 "user:abc123" 或 "ip:192.168.1.1")
path -- 请求路径
method -- HTTP 方法
- 返回:
限流检查结果
- 抛出:
RateLimitExceededError -- 超出限流阈值时