code wiki / (root) / range_header.nx

range_header.nx

buildroot/runtime/range_header.nx

6497 B191 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic range
docsdependenciesstructsconstsfunctions

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

syscalls.nx range_header.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main range_parse rh_parse_uint rh_is_digit

structs

34struct RangeSpec {

consts

30const RH_ERR_FORMAT: i64 = -1
31const RH_ERR_UNIT: i64 = -2
32const RH_ERR_OVERFLOW: i64 = -3

functions

40func rh_is_digit(b: i64) -> i64 {
called by 1: rh_parse_uint
48func rh_parse_uint(buf: *u8, off: *i64, end: i64) -> i64 {
called by 1: range_parse calls 1: rh_is_digit
63func range_parse(buf: *u8, n: i64, total_size: i64,
called by 1: main calls 1: rh_parse_uint
157func main() -> i64 {
calls 1: range_parse