1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// Standard `RateLimit-Limit` response header name.
pub const HEADER_RATE_LIMIT_LIMIT: &str = "ratelimit-limit";
/// Standard `RateLimit-Remaining` response header name.
pub const HEADER_RATE_LIMIT_REMAINING: &str = "ratelimit-remaining";
/// Standard `RateLimit-Reset` response header name (seconds until window/burst reset).
pub const HEADER_RATE_LIMIT_RESET: &str = "ratelimit-reset";
/// Default maximum requests permitted per window.
pub const DEFAULT_RATE_LIMIT_REQUESTS: u64 = 100;
/// Default rate-limit window duration in milliseconds (60 seconds).
pub const DEFAULT_RATE_LIMIT_WINDOW_MS: u64 = 60_000;
/// Default burst capacity when not overridden.
pub const DEFAULT_RATE_LIMIT_BURST: u64 = 100;
/// Default maximum tracked distinct rate-limit keys across all shards.
pub const DEFAULT_RATE_LIMIT_MAX_KEYS: usize = 65_536;
/// Number of independent lock-striped shards (`64`, power of two).
pub const RATE_LIMIT_SHARD_COUNT: usize = 64;
/// Nanoseconds per millisecond conversion factor.
pub const NANOS_PER_MS: u64 = 1_000_000;
/// Nanoseconds per second conversion factor.
pub const NANOS_PER_SEC: u64 = 1_000_000_000;
/// Fallback key used when no peer address or forwarding header is available.
pub const FALLBACK_CLIENT_KEY: &str = "anonymous";
/// Maximum decimal digits needed to format any `u64` on the stack.
pub const U64_STACK_BUF_LEN: usize = 20;
/// Stack buffer capacity in bytes for formatting any IPv4 or IPv6 address without heap allocation.
pub const IP_STACK_BUF_LEN: usize = 64;
/// Maximum header name length lowercased on the stack before falling back to heap allocation.
pub const STACK_HEADER_NAME_LEN: usize = 64;
/// Separator character joining request path and client IP in composite rate-limit keys.
pub const KEY_PATH_IP_SEPARATOR: char = '|';
/// Comma delimiter separating addresses in `X-Forwarded-For` headers.
pub const XFF_COMMA_DELIMITER: char = ',';