code wiki / (root) / nx_http_proxy_probe.nx

nx_http_proxy_probe.nx source

↩ module page · 23 lines · 1373 B

1// nx_http_proxy_probe.nx -- LIVE end-to-end proof of the reverse-proxy: simulate 2// the sites edge receiving "GET /research/work/GBIF_1000003" for nishifamily.com, 3// relay it through nx_http_proxy_relay to the library backend (:8095), and print 4// the response the edge would TLS-send to the browser. 5import "nx_syscalls.nx" 6import "nx_http_proxy.nx" 7const K_MAGIC_262144: i64 = 262144 8const K_MAGIC_8095: i64 = 8095 9 10func pp_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 11 12func main() -> i64 { 13 let req: *u8 = "GET /research/work/GBIF_1000003 HTTP/1.1\r\nHost: nishifamily.com\r\nUser-Agent: browser\r\n\r\n" as *u8 14 let out: *u8 = sys_mmap(K_MAGIC_262144) 15 sys_write(1, "edge got: GET /research/work/GBIF_1000003 (Host nishifamily.com)\n" as *u8, 64) 16 sys_write(1, "relaying via nx_http_proxy_relay -> 127.0.0.1:8095 (strip /research)...\n" as *u8, 71) 17 let n: i64 = nx_http_proxy_relay("127.0.0.1" as *u8, 9, K_MAGIC_8095, "/research" as *u8, 9, req, pp_slen(req), out, K_MAGIC_262144) 18 if n <= 0 { sys_write(1, "relay FAILED (backend not up?)\n" as *u8, 31); return 1 } 19 sys_write(1, "=== response relayed through the sovereign proxy ===\n" as *u8, 52) 20 sys_write(1, out, n) 21 sys_write(1, "\n=== end (edge -> nx_http_proxy -> nx_lib_httpd -> real taxon; nginx-free) ===\n" as *u8, 78) 22 return 0 23}