pub const DEFAULT_MAX_PAYLOAD: usize = 64 * 1024 * 1024;
pub const DEFAULT_MAX_HEADER: usize = 1024 * 1024;
pub const DEFAULT_MAX_STREAM_BUF: usize = 4 * 1024 * 1024;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Limits {
pub max_payload: usize,
pub max_header: usize,
pub max_stream_buf: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
max_payload: DEFAULT_MAX_PAYLOAD,
max_header: DEFAULT_MAX_HEADER,
max_stream_buf: DEFAULT_MAX_STREAM_BUF,
}
}
}
impl Limits {
pub fn strict() -> Self {
Self {
max_payload: 256 * 1024,
max_header: 64 * 1024,
max_stream_buf: 64 * 1024,
}
}
pub fn check_payload(self, len: usize) -> Result<(), String> {
if len > self.max_payload {
Err(format!("payload {len} exceeds limit {}", self.max_payload))
} else {
Ok(())
}
}
}