nx_websocket_upgrade.nx
buildroot/runtime/nx_websocket_upgrade.nx
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
imports: nx_syscalls.nxnx_websocket_handshake.nx
imported by: nx_sig_min_probe.nxnx_signaling_v2.nxnx_websocket_upgrade_test.nx
structs
| none |
consts
| 38 | const NX_WSU_OK: i64 = 1 |
| 39 | const NX_WSU_READ_FAIL: i64 = 2 |
| 40 | const NX_WSU_BAD_METHOD: i64 = 3 |
| 41 | const NX_WSU_BAD_HTTP: i64 = 4 // request line malformed |
| 42 | const NX_WSU_BAD_UPGRADE: i64 = 5 // missing/wrong Upgrade header |
| 43 | const NX_WSU_BAD_CONNECTION: i64 = 6 // missing/wrong Connection header |
| 44 | const NX_WSU_BAD_VERSION: i64 = 7 // missing/wrong Sec-WebSocket-Version |
| 45 | const NX_WSU_BAD_KEY: i64 = 8 // missing/malformed Sec-WebSocket-Key |
| 46 | const NX_WSU_WRITE_FAIL: i64 = 9 |
| 47 | const NX_WSU_HEADERS_TOO_BIG: i64 = 10 |
| 48 | const NX_WSU_VERDICT_N: i64 = 11 |
functions
| 50 | func nx_wsu_verdict_is_valid(v: i64) -> i64 |
| 57 | func _wsu_tolower(c: u8) -> u8 called by 1: _wsu_eq_ci |
| 67 | func _wsu_eq_ci(buf: *u8, off: i64, end: i64, lit: *u8, lit_n: i64) -> i64 |
| 80 | func _wsu_eq_cs(buf: *u8, off: i64, end: i64, lit: *u8, lit_n: i64) -> i64 called by 1: nx_ws_upgrade_handshake |
| 92 | func _wsu_find_header_end(buf: *u8, n: i64) -> i64 called by 1: _wsu_read_headers |
| 110 | func _wsu_read_headers(fd: i64, buf: *u8, cap: i64) -> i64 |
| 123 | func _wsu_write_n(fd: i64, buf: *u8, n: i64) -> i64 |
| 135 | func _wsu_next_line(buf: *u8, start: i64, end: i64) -> i64 called by 1: _wsu_find_header |
| 146 | func _wsu_skip_ws(buf: *u8, start: i64, end: i64) -> i64 called by 1: _wsu_find_header |
| 161 | func _wsu_eol(buf: *u8, start: i64, end: i64) -> i64 |
| 174 | func _wsu_find_byte(buf: *u8, start: i64, end: i64, target: u8) -> i64 called by 1: nx_ws_upgrade_handshake |
| 187 | func _wsu_find_header(buf: *u8, hdr_start: i64, hdr_end: i64, |
| 213 | func nx_ws_upgrade_handshake(fd: i64, called by 3: mainmainmain calls 9: _wsu_read_headers_wsu_eq_cs_wsu_find_byte_wsu_eolsys_mmap_wsu_find_header+3 |
| 330 | func main() -> i64 |