code wiki / (root) / http.nx

http.nx

buildroot/runtime/http.nx

10067 B276 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic http
docsdependenciesstructsconstsfunctions

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 · 0 importers

syscalls.nx http.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main http_parse http_request_init http_parse_request_line http_scan_token_end http_skip_hspace http_find_crlf http_parse_headers http_skip_hspace ↻ http_find_crlf ↻ http_get_header http_header_name_eq

structs

37struct HttpRequest {

consts

26const HTTP_ERR_TRUNCATED: i64 = -1
27const HTTP_ERR_BAD_METHOD: i64 = -2
28const HTTP_ERR_BAD_VERSION: i64 = -3
29const HTTP_ERR_BAD_HEADER: i64 = -4
30const HTTP_ERR_TOO_MANY_HDR: i64 = -5
32const HTTP_MAX_HEADERS: i64 = 64

functions

52func http_request_init(req: *HttpRequest) -> i64 {
called by 1: http_parse
67func http_scan_token_end(buf: *u8, pos: i64, end: i64) -> i64 {
81func http_skip_hspace(buf: *u8, pos: i64, end: i64) -> i64 {
95func http_find_crlf(buf: *u8, pos: i64, end: i64) -> i64 {
110func http_parse_request_line(buf: *u8, end: i64, req: *HttpRequest) -> i64 {
145func http_parse_headers(buf: *u8, start: i64, end: i64,
206func http_parse(buf: *u8, n: i64, req: *HttpRequest) -> i64 {
220func http_header_name_eq(buf: *u8, off: i64, len: i64,
called by 1: http_get_header
241func http_get_header(buf: *u8, req: *HttpRequest, name: *u8,
called by 1: main calls 1: http_header_name_eq
257func main() -> i64 {