code wiki / (root) / nx_https_redirect.nx

nx_https_redirect.nx source

↩ module page · 45 lines · 2011 B

1// nx_https_redirect.nx -- Fetcher upgrade F-1: SOVEREIGN redirect handling. 2// 3// The live HTTPS fetcher (nx_https_get/_complete) returns a parsed response but 4// does NOT follow 3xx redirects -- a verified gap that blocks most modern docs 5// (http->https, trailing-slash, www, CDN hops). This organ adds the decision + 6// Location extraction; nx_https_fetch_follow (F-2) loops it over the live fetch. 7// 100% sovereign: composes nx_http_header_find (no 3rd-party). The only non-Nishi 8// inputs anywhere are unavoidable DATA (CA roots, fetched pages), never code. 9// 10// nx_safety_envelope: 11// intended_use: sovereign web fetcher (pure: status + header bytes -> decision) 12// sil_target: SIL1 13// verdict: NOT_YET_EVALUATED 14// genealogy_id: ietf/rfc_9110_redirects lineage_id: nx_https_redirect_v1 15 16import "nx_syscalls.nx" 17import "nx_http_header_find.nx" 18 19// Is this status a redirect we should follow? (RFC 9110: 301/302/303/307/308) 20func nx_redir_is_redirect(status: i64) -> i64 { 21 if status == 301 { return 1 } 22 if status == 302 { return 1 } 23 if status == 303 { return 1 } 24 if status == 307 { return 1 } 25 if status == 308 { return 1 } 26 return 0 27} 28 29// Extract the Location header value into out (NUL-terminated). Returns the 30// length, or 0 if absent / malformed / too long. `resp` is the response bytes 31// starting at the status line (nx_http_header_find skips the status line). 32func nx_redir_location(resp: *u8, resp_n: i64, out: *u8, out_cap: i64) -> i64 { 33 let off_box: *i64 = (sys_mmap(8)) as *i64 34 let len_box: *i64 = (sys_mmap(8)) as *i64 35 let v: i64 = nx_http_header_find(resp, resp_n, "Location" as *u8, 8, off_box, len_box) 36 if v != 0 { return 0 } // NXHF_FOUND == 0; anything else = absent 37 let vlen: i64 = len_box[0] 38 if vlen <= 0 { return 0 } 39 if vlen >= out_cap { return 0 } 40 let voff: i64 = off_box[0] 41 var i: i64 = 0 42 while i < vlen { out[i] = resp[voff + i]; i = i + 1 } 43 out[vlen] = 0 as u8 44 return vlen 45}