code wiki / (root) / nx_content_type.nx

nx_content_type.nx

buildroot/runtime/nx_content_type.nx

5463 B173 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic content
docsdependenciesstructsconstsfunctions

about

content_type.nx -- parse a Content-Type / Accept header value. RFC 7231 ยง3.1.1.1. A media-type value is: type "/" subtype *( ";" param "=" value ) Examples: text/html text/html; charset=utf-8 multipart/form-data; boundary=----WebKitFormBoundary application/vnd.nishi.page+json; profile=blog Parses this into (type_off, type_len, subtype_off, subtype_len, params_off, params_len) triplets. Parameter list is left as a raw byte range -- caller can feed it into cookie.nx or query.nx style splitters if it needs per-param access. For most routing, knowing the type + subtype is enough. The Accept header uses the same grammar with an additional "q=" parameter for quality (0..1). We surface the parsed param range so caller can extract "q" on demand. Invariants: CT1 Type + subtype trimmed of surrounding whitespace. CT2 Type + subtype lowercased-in-place is CALLER's job (we're zero-alloc; won't mutate the buffer). CT3 Missing '/' returns CT_ERR_FORMAT; media types always have a slash. CT4 "*/*", "text/*", "application/*": accepted as-is; caller inspects for '*' to know whether it's a wildcard.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_content_type.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap content_type_parse ct_ltrim ct_is_ws ct_rtrim ct_is_ws ↻ if_neg_else content_type_is

structs

41struct ContentType

consts

39const CT_ERR_FORMAT: i64 = -1

functions

49func ct_is_ws(b: i64) -> i64
called by 2: ct_ltrimct_rtrim
55func ct_ltrim(buf: *u8, off: i64, end: i64) -> i64
called by 1: content_type_parse calls 1: ct_is_ws
64func ct_rtrim(buf: *u8, start: i64, end: i64) -> i64
called by 1: content_type_parse calls 1: ct_is_ws
74func if_neg_else(a: i64, b: i64) -> i64;
called by 1: content_type_parse
77func content_type_parse(buf: *u8, n: i64, ct: *ContentType) -> i64
called by 1: main calls 3: ct_ltrimct_rtrimif_neg_else
122func if_neg_else(a: i64, b: i64) -> i64
131func content_type_is(buf: *u8, ct: *ContentType,
called by 1: main
150func main() -> i64