nx_cors.nx
buildroot/runtime/nx_cors.nx
about
cors.nx -- build CORS response headers.
Fetch / XHR from a browser to a cross-origin server triggers
CORS (Cross-Origin Resource Sharing). Browser sends a preflight
OPTIONS request with Origin + Access-Control-Request-Method +
Access-Control-Request-Headers. Server answers with Access-
Control-Allow-* headers indicating what's permitted.
Spec: Fetch Living Standard §Cors (supersedes the W3C CORS rec).
Typical minimal response for a permissive public API:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 86400
For credentialed requests (cookies / auth), Allow-Origin MUST
echo the specific origin (not '*') and Allow-Credentials MUST
be true. We expose both modes.
Invariants:
CO1 Stream builder; caller supplies an output buffer + offset.
CO2 Headers include trailing CRLF; caller concatenates them
after the HTTP status line.
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
| none |
consts
| 33 | const CORS_MAGIC_86400: i64 = 86400 |
| 34 | const CORS_MAGIC_1024: i64 = 1024 |
| 36 | const CORS_ERR_SHORT: i64 = -1 |
functions
| 38 | func co_put(out: *u8, cap: i64, off: i64, src: *u8, n: i64) -> i64 |
| 50 | func cors_allow_origin(out: *u8, cap: i64, off: i64, |
| 63 | func cors_allow_methods(out: *u8, cap: i64, off: i64, |
| 76 | func cors_allow_headers(out: *u8, cap: i64, off: i64, |
| 89 | func cors_expose_headers(out: *u8, cap: i64, off: i64, calls 1: co_put |
| 102 | func cors_allow_credentials(out: *u8, cap: i64, off: i64) -> i64 calls 1: co_put |
| 110 | func cors_max_age(out: *u8, cap: i64, off: i64, seconds: i64) -> i64 |
| 143 | func cors_permissive(out: *u8, cap: i64, off: i64) -> i64 |
| 158 | func main() -> i64 |