nx_range_header.nx
buildroot/runtime/nx_range_header.nx
about
range_header.nx -- parse HTTP Range request header.
RFC 7233 ยง3.1. Range requests let a client ask for a byte
range of a resource instead of the whole thing. Essential for:
- Video / audio seeking (HTML5 <video> sends Range requests
when you click the scrubber)
- Resumable downloads (browsers retry interrupted downloads
with \"Range: bytes=<last-byte-received>-\")
- Large-file diff tools
Format (most useful forms):
Range: bytes=0-499 <- first 500 bytes
Range: bytes=500- <- byte 500 to end
Range: bytes=-500 <- last 500 bytes
Range: bytes=0-499,1000-1499 <- multiple ranges (multipart)
We only support bytes= unit; other units (chars=, seconds=
in some video specs) are non-standard and rare.
Invariants:
RH1 Returns RangeSpec array with (start, end) resolved vs
the file size. "-500" -> (size-500, size-1).
"500-" -> (500, size-1).
RH2 Ranges that extend past the file are clamped.
RH3 Empty / unparseable input returns RH_ERR_FORMAT so
caller falls back to serving 200 with full body.
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 41 | struct RangeSpec |
consts
| 35 | const RH_MAGIC_7233: i64 = 7233 |
| 37 | const RH_ERR_FORMAT: i64 = -1 |
| 38 | const RH_ERR_UNIT: i64 = -2 |
| 39 | const RH_ERR_OVERFLOW: i64 = -3 |
functions
| 47 | func rh_is_digit(b: i64) -> i64 called by 1: rh_parse_uint |
| 55 | func rh_parse_uint(buf: *u8, off: *i64, end: i64) -> i64 |
| 70 | func range_parse(buf: *u8, n: i64, total_size: i64, |
| 164 | func main() -> i64 |