a06673b
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RateLimitConfig {
/// Default per-api request limit within the window.
pub default_limit: u64,
/// Sliding window length in seconds.
pub window_secs: i64,
/// Name of the dedicated rate-limit cookie (server-side partition key).
pub cookie_name: String,
/// Whether the rate-limit cookie should carry the Secure flag.
pub cookie_secure: bool,
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
default_limit: 100,
window_secs: 60,
cookie_name: "rl_id".to_string(),
cookie_secure: true,
}
}
}
impl RateLimitConfig {
pub fn new(default_limit: u64, window_secs: i64) -> Self {
Self {
default_limit,
window_secs,
..Self::default()
}
}
}