code wiki / (root) / nx_https_get_stream.nx

nx_https_get_stream.nx

buildroot/runtime/nx_https_get_stream.nx

9440 B163 linesdepth 11pulls 40 transitivereach 13 importersview sourcekind tooltopic https
docsdependenciesstructsconstsfunctions

about

nx_https_get_stream.nx -- STREAMING TLS GET (the M3-into-fetch piece): parse response headers, then stream the body straight to a dest fd. Multi-GB shards flow fetch -> decrypt -> disk through a small window, no 5GB buffer. S-CLASS features: RESUME (range_start>0 -> "Range: bytes=N-" header, so a broken partial continues); WRITE- BUFFERING (batch body into 8MB writes -> ~500x fewer 9p/NAS syscalls = faster + doesn't destabilize the mount); redirect-aware (3xx -> Location); range-safety (a full 200 to a ranged request -> -9 so the caller truncates + restarts, never appending a full body onto a partial). No sha256 here (M32 clash with TLS crypto -> verify in a separate organ). Mirrors nx_https_get_complete's proven send + read/decrypt loop (only the sink changes). ORIGINAL

dependencies 7 imports · 8 importers

nx_syscalls.nx nx_tls13.nx nx_tls13_record.nx nx_tls13_read_record_from_fd.nx nx_tls13_client_session.nx nx_http_client.nx nx_chacha20_poly1305.nx nx_https_get_stream.nx nx_apertus_mirror_nas.nx nx_apertus_shards_pull.nx nx_hf_file_fetch.nx nx_hifigan_stream_fetch.nx nx_https_fetch_file.nx nx_https_fetch_lib.nx nx_par_pull.nx nx_par_pull_nas.nx

imports: nx_syscalls.nxnx_tls13.nxnx_tls13_record.nxnx_tls13_read_record_from_fd.nxnx_tls13_client_session.nxnx_http_client.nxnx_chacha20_poly1305.nx

imported by: nx_apertus_mirror_nas.nxnx_apertus_shards_pull.nxnx_hf_file_fetch.nxnx_hifigan_stream_fetch.nxnx_https_fetch_file.nxnx_https_fetch_lib.nxnx_par_pull.nxnx_par_pull_nas.nx

structs

none

consts

16const NX_GS_REQ_BUF_BYTES: i64 = 4096
17const NX_GS_RESP_RECORD_BYTES: i64 = 16645
18const NX_GS_HDR_CAP: i64 = 65536
19const NX_GS_WBUF_CAP: i64 = 67108864

functions

21func gs_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: gs_ci_match
22func gs_puts(buf: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){buf[o]=s[i];o=o+1;i=i+1} return o }
called by 1: nx_https_get_stream
23func gs_wdec(buf: *u8, off: i64, v: i64) -> i64 { var o: i64=off; if v==0 { buf[o]=48 as u8; return o+1 } let t:*u8=sys_mmap(24); var k:i64=0; var m:i64=v; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var j:i64=k-1; while j>=0 { buf[o]=t[j]; o=o+1; j=j-1 } return o }
called by 1: nx_https_get_stream calls 1: sys_mmap
24func gs_write_n(fd: i64, buf: *u8, n: i64) -> i64 { var off: i64=0; while off < n { let r: i64=sys_write(fd, ((buf as i64)+off) as *u8, n-off); if r <= 0 { return 0-1 } off = off + r } return 0 }
26func gs_bufapp(wbuf: *u8, wlenp: *i64, dest_fd: i64, src: *u8, n: i64) -> i64
called by 1: nx_https_get_stream calls 1: gs_write_n
36func gs_hdr_end(buf: *u8, n: i64) -> i64 { var i: i64=0; while i+4 <= n { if buf[i]==(13 as u8){ if buf[i+1]==(10 as u8){ if buf[i+2]==(13 as u8){ if buf[i+3]==(10 as u8){ return i } } } } i=i+1 } return 0-1 }
called by 1: nx_https_get_stream
37func gs_status(buf: *u8, n: i64) -> i64 { if n < 12 { return 0 } return ((buf[9] as i64)-48)*100 + ((buf[10] as i64)-48)*10 + ((buf[11] as i64)-48) }
called by 1: nx_https_get_stream
38func gs_ci_match(buf: *u8, off: i64, end: i64, pat: *u8, patlen: i64) -> i64 { if off+patlen > end { return 0 } var j: i64=0; while j < patlen { if gs_lc(buf[off+j] as i64) != gs_lc(pat[j] as i64) { return 0 } j=j+1 } return 1 }
called by 2: gs_clengs_location calls 1: gs_lc
39func gs_clen(buf: *u8, hdr_end: i64) -> i64
called by 1: nx_https_get_stream calls 1: gs_ci_match
57func gs_location(buf: *u8, hdr_end: i64, out: *u8, out_cap: i64) -> i64
called by 1: nx_https_get_stream calls 1: gs_ci_match
75func nx_https_get_stream(s: *Tls13ClientSession, fd: i64, path: *u8, path_len: i64, host: *u8, host_len: i64,
163func main() -> i64 { return 0 }