pub const JSON_REQUEST_MAX: u64 = 32 * 1024 * 1024;
pub const JSON_RESPONSE_MAX: u64 = 32 * 1024 * 1024;
pub const ERROR_BODY_MAX: u64 = 64 * 1024;
pub const SSE_LINE_MAX: u64 = 1024 * 1024;
pub const SSE_EVENT_MAX: u64 = 1024 * 1024;
pub const SSE_BUFFER_MAX: u64 = 1024 * 1024;
pub const MULTIPART_MAX_FILE_PARTS: usize = 16;
pub const MULTIPART_FILE_BYTES_MAX: u64 = 128 * 1024 * 1024;
pub const MULTIPART_FIELD_BYTES_MAX: u64 = 1024 * 1024;
pub const WS_MESSAGE_MAX: u64 = 8 * 1024 * 1024;
pub const WS_FRAME_MAX: u64 = 2 * 1024 * 1024;
pub const REALTIME_AUDIO_FRAME_MAX: u64 = 4 * 1024 * 1024;
pub const REQUEST_ID_MAX: usize = 128;
pub const API_CODE_TEXT_MAX: usize = 128;
#[derive(Debug, Clone, Copy)]
pub struct Limit {
pub bytes: u64,
}
impl Limit {
pub fn clamp(requested: u64, hard: u64) -> Self {
Self {
bytes: requested.min(hard),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn json_limits_match_plan() {
assert_eq!(JSON_REQUEST_MAX, 32 * 1024 * 1024);
assert_eq!(JSON_RESPONSE_MAX, 32 * 1024 * 1024);
assert_eq!(ERROR_BODY_MAX, 64 * 1024);
assert_eq!(SSE_LINE_MAX, 1024 * 1024);
assert_eq!(MULTIPART_FILE_BYTES_MAX, 128 * 1024 * 1024);
assert_eq!(WS_MESSAGE_MAX, 8 * 1024 * 1024);
assert_eq!(REALTIME_AUDIO_FRAME_MAX, 4 * 1024 * 1024);
}
#[test]
fn clamp_never_exceeds_hard_cap() {
assert_eq!(Limit::clamp(100, 50).bytes, 50);
assert_eq!(Limit::clamp(50, 100).bytes, 50);
assert_eq!(Limit::clamp(100, 100).bytes, 100);
}
}