nx_content_type.nx
buildroot/runtime/nx_content_type.nx
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
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
structs
| 41 | struct ContentType |
consts
| 39 | const CT_ERR_FORMAT: i64 = -1 |
functions
| 49 | func ct_is_ws(b: i64) -> i64 |
| 55 | func ct_ltrim(buf: *u8, off: i64, end: i64) -> i64 |
| 64 | func ct_rtrim(buf: *u8, start: i64, end: i64) -> i64 |
| 74 | func if_neg_else(a: i64, b: i64) -> i64; called by 1: content_type_parse |
| 77 | func content_type_parse(buf: *u8, n: i64, ct: *ContentType) -> i64 |
| 122 | func if_neg_else(a: i64, b: i64) -> i64 |
| 131 | func content_type_is(buf: *u8, ct: *ContentType, called by 1: main |
| 150 | func main() -> i64 |