multipartkit/limit
Types
Why a Limits value could not be constructed.
Returned by new when a field receives a non-positive value.
field names the offending field so a single handler can produce a
meaningful error message even when several limits are misconfigured
at once (the first failing field stops further checks).
pub type LimitConfigError {
NonPositiveLimit(field: String, given: Int)
}
Constructors
-
NonPositiveLimit(field: String, given: Int)
Limits applied during parsing to bound resource consumption.
All limits are inclusive: a value equal to the limit is allowed; the
(limit + 1)-th byte / part triggers the error.
Construct via new (validated, recommended) or default (conservative
presets). Direct Limits(...) construction stays available for
trusted callers, but new is the supported path for any value sourced
from configuration, request input, or other dynamic input.
pub type Limits {
Limits(
max_body_bytes: Int,
max_part_bytes: Int,
max_parts: Int,
max_header_bytes: Int,
)
}
Constructors
-
Limits( max_body_bytes: Int, max_part_bytes: Int, max_parts: Int, max_header_bytes: Int, )Arguments
- max_body_bytes
-
Total bytes consumed from input, including boundary delimiters, preamble, epilogue, and per-part header blocks. Triggers
BodyTooLarge. - max_part_bytes
-
Bytes of a single part body excluding the part’s header block and the surrounding boundary lines. Triggers
PartTooLarge. - max_parts
-
Maximum number of parts produced. Triggers
TooManyPartswhen the(limit + 1)-th part is detected. - max_header_bytes
-
Total bytes of one part’s complete header block, measured from the byte after the boundary delimiter line up to and including the blank line that terminates the header block. Triggers
HeaderTooLarge.
Values
pub fn default_limits() -> Limits
Conservative defaults used by parse and parse_stream when no explicit
limits are supplied.
pub fn max_body_bytes(limits: Limits) -> Int
Total-input byte budget. See Limits.max_body_bytes.
pub fn max_header_bytes(limits: Limits) -> Int
Per-part header-block byte budget. See Limits.max_header_bytes.
pub fn max_part_bytes(limits: Limits) -> Int
Per-part body byte budget. See Limits.max_part_bytes.
pub fn max_parts(limits: Limits) -> Int
Maximum number of parts. See Limits.max_parts.
pub fn new(
max_body_bytes max_body_bytes: Int,
max_part_bytes max_part_bytes: Int,
max_parts max_parts: Int,
max_header_bytes max_header_bytes: Int,
) -> Result(Limits, LimitConfigError)
Construct a Limits value with validation. Each field must be >= 1;
otherwise the returned Error names the first failing field.
Use this in any path where the limit values come from configuration,
CLI flags, request input, or other dynamic input. For trusted
constants the direct Limits(...) constructor is also fine, but
callers that want a stable surface ahead of the Limits type being
closed (see the upcoming opaque-type work) should prefer new.
Example: import multipartkit/limit
case limit.new( max_body_bytes: 5_000_000, max_part_bytes: 2_000_000, max_parts: 50, max_header_bytes: 8_192, ) { Ok(limits) -> … Error(limit.NonPositiveLimit(field: f, given: g)) -> … }