code wiki / (root) / nx_cors.nx

nx_cors.nx

buildroot/runtime/nx_cors.nx

6146 B175 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_cors.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 cors_permissive cors_allow_origin co_put cors_allow_methods co_put ↻ cors_allow_headers co_put ↻ cors_max_age co_put ↻ sys_mmap ↻ cors_allow_origin ↻

structs

none

consts

33const CORS_MAGIC_86400: i64 = 86400
34const CORS_MAGIC_1024: i64 = 1024
36const CORS_ERR_SHORT: i64 = -1

functions

38func co_put(out: *u8, cap: i64, off: i64, src: *u8, n: i64) -> i64
50func cors_allow_origin(out: *u8, cap: i64, off: i64,
called by 2: cors_permissivemain calls 1: co_put
63func cors_allow_methods(out: *u8, cap: i64, off: i64,
called by 1: cors_permissive calls 1: co_put
76func cors_allow_headers(out: *u8, cap: i64, off: i64,
called by 1: cors_permissive calls 1: co_put
89func cors_expose_headers(out: *u8, cap: i64, off: i64,
calls 1: co_put
102func cors_allow_credentials(out: *u8, cap: i64, off: i64) -> i64
calls 1: co_put
110func cors_max_age(out: *u8, cap: i64, off: i64, seconds: i64) -> i64
called by 1: cors_permissive calls 2: co_putsys_mmap
143func cors_permissive(out: *u8, cap: i64, off: i64) -> i64
158func main() -> i64