nx_https_get_cli2_body_gate.nx source
↩ module page · 44 lines · 4712 B
1import "nx_https_get_cli2_candidate.nx"
2func main() -> i64 {
3 let c0: *u8="HTTP/1.1 200 OK\r\nX-Note: chunked\r\nContent-Length: 2\r\n\r\nOK" as *u8
4 if hgc_hdr_chunked(c0,hgc_slen(c0),hgc_hdr_end(c0,hgc_slen(c0))) != 0 { hgc_put("FAIL coding 0\n" as *u8); return 1 }
5 let c1: *u8="HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n" as *u8
6 if hgc_hdr_chunked(c1,hgc_slen(c1),hgc_hdr_end(c1,hgc_slen(c1))) != 1 { hgc_put("FAIL coding 1\n" as *u8); return 1 }
7 let c2: *u8="HTTP/1.1 200 OK\r\ntRaNsFeR-EnCoDiNg:\tChUnKeD \t\r\n\r\n0\r\n\r\n" as *u8
8 if hgc_hdr_chunked(c2,hgc_slen(c2),hgc_hdr_end(c2,hgc_slen(c2))) != 1 { hgc_put("FAIL coding 2\n" as *u8); return 1 }
9 let c3: *u8="HTTP/1.1 200 OK\r\nX-Transfer-Encoding: chunked\r\n\r\nOK" as *u8
10 if hgc_hdr_chunked(c3,hgc_slen(c3),hgc_hdr_end(c3,hgc_slen(c3))) != 0 { hgc_put("FAIL coding 3\n" as *u8); return 1 }
11 let c4: *u8="HTTP/1.1 200 OK\r\n\r\nTransfer-Encoding: chunked" as *u8
12 if hgc_hdr_chunked(c4,hgc_slen(c4),hgc_hdr_end(c4,hgc_slen(c4))) != 0 { hgc_put("FAIL coding 4\n" as *u8); return 1 }
13 let c5: *u8="HTTP/1.1 200 OK\r\nTransfer-Encoding: gzip, chunked\r\n\r\n" as *u8
14 if hgc_hdr_chunked(c5,hgc_slen(c5),hgc_hdr_end(c5,hgc_slen(c5))) != -1 { hgc_put("FAIL coding 5\n" as *u8); return 1 }
15 let c6: *u8="HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nTransfer-Encoding: chunked\r\n\r\n" as *u8
16 if hgc_hdr_chunked(c6,hgc_slen(c6),hgc_hdr_end(c6,hgc_slen(c6))) != -1 { hgc_put("FAIL coding 6\n" as *u8); return 1 }
17 let c7: *u8="HTTP/1.1 200 OK\r\nTransfer-Encoding: xchunked\r\n\r\n" as *u8
18 if hgc_hdr_chunked(c7,hgc_slen(c7),hgc_hdr_end(c7,hgc_slen(c7))) != -1 { hgc_put("FAIL coding 7\n" as *u8); return 1 }
19 let input: *u8=sys_mmap(HGC_XHDR_CAP+1)
20 let output: *u8=sys_mmap(HGC_XHDR_CAP+1)
21 var i: i64=0
22 while i < HGC_XHDR_CAP { input[i]=65 as u8; i=i+1 }
23 input[1]=58 as u8
24 output[HGC_XHDR_CAP]=99 as u8
25 input[HGC_XHDR_CAP-2]=0 as u8
26 if hgc_build_xhdr(input,output) != HGC_XHDR_CAP { hgc_put("FAIL header exact capacity\n" as *u8); return 1 }
27 input[HGC_XHDR_CAP-2]=65 as u8
28 if hgc_build_xhdr(input,output) != HGC_HDR_ERR_CAPACITY { hgc_put("FAIL header overflow refusal\n" as *u8); return 1 }
29 if output[HGC_XHDR_CAP] != 99 as u8 { hgc_put("FAIL output canary\n" as *u8); return 1 }
30 if hgc_build_xhdr("X: a\r\nInjected: b" as *u8,output) != HGC_HDR_ERR_CTLBYTE { return 1 }
31 if hgc_dechunk("1\r\nAxx0\r\n\r\n" as *u8,11,output) >= 0 { hgc_put("FAIL shared decoder integration\n" as *u8); return 1 }
32 let live_response: *u8="HTTP/1.1 200 OK\r\nDate: Tue, 08 Sep 2026 14:37:07 GMT\r\nContent-Type: text/html\r\nTransfer-Encoding: chunked\r\nConnection: close\r\nServer: cloudflare\r\nlast-modified: Wed, 02 Sep 2026 22:14:26 GMT\r\nallow: GET, HEAD\r\nAccept-Ranges: bytes\r\nAge: 4709\r\ncf-cache-status: HIT\r\nCF-RAY: a37eb07aed226a08-DFW\r\n\r\n22f\r\n<!doctype html><html lang=\"en\"><head><title>Example Domain</title><link rel=\"icon\" href=\"data:,\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style></head><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.</p><p><a href=\"https://iana.org/domains/example\">Learn more</a></p></div></body></html>\n\r\n0\r\n\r\n" as *u8
33 let live_n: i64=hgc_slen(live_response)
34 let live_he: i64=hgc_hdr_end(live_response,live_n)
35 if live_he < 0 { return 1 }
36 if hgc_hdr_chunked(live_response,live_n,live_he) != 1 { return 1 }
37 let live_decoded: i64=hgc_dechunk(live_response+live_he,live_n-live_he,output)
38 let live_expected: *u8="<!doctype html><html lang=\"en\"><head><title>Example Domain</title><link rel=\"icon\" href=\"data:,\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style></head><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.</p><p><a href=\"https://iana.org/domains/example\">Learn more</a></p></div></body></html>\n" as *u8
39 if live_decoded != hgc_slen(live_expected) { hgc_put("FAIL captured origin body length\n" as *u8); return 1 }
40 var live_i: i64=0
41 while live_i < live_decoded { if output[live_i] != live_expected[live_i] { hgc_put("FAIL captured origin body bytes\n" as *u8); return 1 }; live_i=live_i+1 }
42 hgc_put("PASS: coding, header bounds, shared decoder and captured HTTP200 body\n" as *u8)
43 return 0
44}