nx_http.nx
buildroot/runtime/nx_http.nx
about
http.nx -- HTTP/1.1 request parser (RFC 7230/9112 subset).
Parses an HTTP request from a byte buffer (typically accumulated
from socket reads). Reader-only subset:
- Request line: METHOD SP path SP HTTP/1.1 CRLF
- Headers: Name ": " Value CRLF (until empty line)
- Body: remaining bytes per Content-Length
Response generation is the caller's job; we provide a typed
view of the request + a Content-Length header lookup helper.
Real-world HTTP servers add: chunked transfer, keep-alive,
HTTP/2 framing, pipelining. Those are future work.
Invariants:
H1 All reads bounds-check against caller-supplied buffer end.
H2 Header parsing stops at CRLF CRLF (empty line) per
RFC 7230 ยง3.
H3 Returns offsets into the caller's buffer; nothing copied.
Parser struct owns only position metadata.
H4 Malformed input returns negative HTTP_ERR_*; no silent
acceptance of weird forms (e.g. bare LF line ends).
dependencies 1 imports · 7 importers
imports: nx_syscalls.nx
imported by: nx_browser_view_serve.nxnx_pages_daemon.nxnx_pages_http_redirect.nxnx_pages_https_daemon.nxnx_pages_vhost.nxnx_pages_vhost_debug.nxnx_pages_vhost_test.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 43 | struct HttpRequest |
consts
| 32 | const HTTP_ERR_TRUNCATED: i64 = -1 |
| 33 | const HTTP_ERR_BAD_METHOD: i64 = -2 |
| 34 | const HTTP_ERR_BAD_VERSION: i64 = -3 |
| 35 | const HTTP_ERR_BAD_HEADER: i64 = -4 |
| 36 | const HTTP_ERR_TOO_MANY_HDR: i64 = -5 |
| 38 | const HTTP_MAX_HEADERS: i64 = 64 |
functions
| 58 | func http_request_init(req: *HttpRequest) -> i64 |
| 73 | func http_scan_token_end(buf: *u8, pos: i64, end: i64) -> i64 |
| 87 | func http_skip_hspace(buf: *u8, pos: i64, end: i64) -> i64 |
| 109 | func http_find_crlf(buf: *u8, pos: i64, end: i64) -> i64 |
| 124 | func http_parse_request_line(buf: *u8, end: i64, req: *HttpRequest) -> i64 |
| 159 | func http_parse_headers(buf: *u8, start: i64, end: i64, |
| 230 | func http_parse(buf: *u8, n: i64, req: *HttpRequest) -> i64 |
| 244 | func http_header_name_eq(buf: *u8, off: i64, len: i64, called by 1: http_get_header |
| 265 | func http_get_header(buf: *u8, req: *HttpRequest, name: *u8, |
| 281 | func main() -> i64 |