pub fn resolve(
h: &RangeHeader<'_>,
length: u64,
coalesce: bool,
limits: &Limits,
out: &mut [ByteRange],
) -> RangeOutcomeExpand description
Resolves a parsed Range against a representation of length bytes.
Suffix ranges become absolute; a last position beyond the end is clamped;
a range starting at or after the end, and a zero-length suffix, are
dropped. More than Limits::max_ranges ranges, more than two ranges
that overlap another, or more than two ranges that start before the one
before them give RangeOutcome::Ignore (RFC 9110 section 14.2 allows
ignoring abusive sets). With coalesce, overlapping and adjacent ranges
are merged into ascending order (this changes the shape of a multipart
response, so it is the caller’s choice). An out too small for the
ranges gives Ignore: the set is never silently truncated.
§Examples
use parse_net::{range, ByteRange, Limits, RangeOutcome};
let h = range::parse(b"bytes=0-10, 5-20, 40-49", &Limits::DEFAULT)?;
let mut out = [ByteRange { start: 0, end: 0 }; 4];
assert_eq!(range::resolve(&h, 100, true, &Limits::DEFAULT, &mut out), RangeOutcome::Ranges(2));
assert_eq!(out[..2], [ByteRange { start: 0, end: 20 }, ByteRange { start: 40, end: 49 }]);