Expand description
Range, Content-Range, and If-Range (RFC 9110 section 14), with
resolution against a representation length and budgets against abusive
range sets.
§Examples
use parse_net::{self as pn, ByteRange, RangeOutcome, range};
let mut out = [ByteRange { start: 0, end: 0 }; 8];
assert_eq!(pn::byte_ranges(b"bytes=0-99, -100", 1000, &mut out)?, RangeOutcome::Ranges(2));
assert_eq!(out[1], ByteRange { start: 900, end: 999 });
assert_eq!(pn::byte_ranges(b"bytes=2000-", 1000, &mut out)?, RangeOutcome::Unsatisfiable);
assert_eq!(pn::byte_ranges(b"items=0-5", 1000, &mut out)?, RangeOutcome::NotBytes);
let mut buf = [0u8; 32];
let mut sink = pn::SliceSink::new(&mut buf);
range::write_content_range(out[0], Some(1000), &mut sink).expect("room");
assert_eq!(sink.written(), b"bytes 0-99/1000");Structs§
- Byte
Range - A resolved byte range, both ends inclusive.
- Range
Header - A validated
Rangevalue.
Enums§
- Content
Range - A parsed
Content-Rangevalue. - IfRange
- A parsed
If-Rangevalue. - Range
Outcome - What to do with a
Rangerequest. - Range
Spec - One
range-specof abytesrange set.
Functions§
- byte_
ranges - Parses and resolves
Rangeagainstlengthwith the default limits and no coalescing. - parse
- Parses
range-unit "=" range-set(RFC 9110 section 14.1.2). - parse_
content_ range - Parses
Content-Range(RFC 9110 section 14.4) for thebytesunit. - parse_
if_ range - Parses
If-Range: an entity tag when the value starts withW/or", an IMF-fixdate otherwise. - resolve
- Resolves a parsed
Rangeagainst a representation oflengthbytes. - write_
content_ range - Writes
bytes first-last/complete, orbytes first-last/*when the complete length is unknown. - write_
unsatisfied - Writes
bytes */complete, for a 416 response.