code wiki / (root) / nx_websocket_upgrade.nx

nx_websocket_upgrade.nx

buildroot/runtime/nx_websocket_upgrade.nx

12087 B332 linesdepth 4pulls 5 transitivereach 3 importersview sourcekind tooltopic websocket
docsdependenciesstructsconstsfunctions

about

nx_websocket_upgrade.nx -- server-side WebSocket HTTP upgrade driver. RFC 6455 §4.1 + §4.2. Reads the client's HTTP/1.1 GET + Upgrade: websocket request from a TCP fd, validates the required headers, computes Sec-WebSocket-Accept via the KAT'd nx_websocket_handshake module, and writes the 101 Switching Protocols response back to the fd. After this returns OK, the caller can use nx_websocket_stream's framer for the binary channel. Required client headers (RFC 6455 §4.1): GET <path> HTTP/1.1 Host: <host> (RFC allows any host; we don't gate) Upgrade: websocket (case-insensitive match required) Connection: Upgrade (case-insensitive; may also be a list) Sec-WebSocket-Key: <24-char base64 of 16 random bytes> Sec-WebSocket-Version: 13 (we only support 13 per RFC 6455) Response (RFC 6455 §4.2.2): HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: base64(sha1(key || GUID)) Per Cardinals 9 (single-responsibility: ONE upgrade per call), 12 (defensive at boundary: every header validated), 22 (composes nx_websocket_handshake + nx_websocket_stream's write helper). Caller writes the path bytes out via out_path_buf (caller-supplied) so the signaling daemon can route by URL. genealogy_id: rfc_6455 + nx_websocket_handshake + nx_edge_v0_read_request_q10 lineage_id: nishi_websocket_upgrade_q1

dependencies 2 imports · 3 importers

nx_syscalls.nx nx_websocket_handshake.nx nx_websocket_upgrade.nx nx_sig_min_probe.nx nx_signaling_v2.nx nx_websocket_upgrade_test.nx

imports: nx_syscalls.nxnx_websocket_handshake.nx

imported by: nx_sig_min_probe.nxnx_signaling_v2.nxnx_websocket_upgrade_test.nx

structs

none

consts

38const NX_WSU_OK: i64 = 1
39const NX_WSU_READ_FAIL: i64 = 2
40const NX_WSU_BAD_METHOD: i64 = 3
41const NX_WSU_BAD_HTTP: i64 = 4 // request line malformed
42const NX_WSU_BAD_UPGRADE: i64 = 5 // missing/wrong Upgrade header
43const NX_WSU_BAD_CONNECTION: i64 = 6 // missing/wrong Connection header
44const NX_WSU_BAD_VERSION: i64 = 7 // missing/wrong Sec-WebSocket-Version
45const NX_WSU_BAD_KEY: i64 = 8 // missing/malformed Sec-WebSocket-Key
46const NX_WSU_WRITE_FAIL: i64 = 9
47const NX_WSU_HEADERS_TOO_BIG: i64 = 10
48const NX_WSU_VERDICT_N: i64 = 11

functions

50func nx_wsu_verdict_is_valid(v: i64) -> i64
57func _wsu_tolower(c: u8) -> u8
called by 1: _wsu_eq_ci
67func _wsu_eq_ci(buf: *u8, off: i64, end: i64, lit: *u8, lit_n: i64) -> i64
80func _wsu_eq_cs(buf: *u8, off: i64, end: i64, lit: *u8, lit_n: i64) -> i64
92func _wsu_find_header_end(buf: *u8, n: i64) -> i64
called by 1: _wsu_read_headers
110func _wsu_read_headers(fd: i64, buf: *u8, cap: i64) -> i64
123func _wsu_write_n(fd: i64, buf: *u8, n: i64) -> i64
called by 1: nx_ws_upgrade_handshake calls 1: sys_write
135func _wsu_next_line(buf: *u8, start: i64, end: i64) -> i64
called by 1: _wsu_find_header
146func _wsu_skip_ws(buf: *u8, start: i64, end: i64) -> i64
called by 1: _wsu_find_header
161func _wsu_eol(buf: *u8, start: i64, end: i64) -> i64
174func _wsu_find_byte(buf: *u8, start: i64, end: i64, target: u8) -> i64
187func _wsu_find_header(buf: *u8, hdr_start: i64, hdr_end: i64,
213func nx_ws_upgrade_handshake(fd: i64,
330func main() -> i64