cors.nx
buildroot/runtime/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: 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
| 28 | const CORS_ERR_SHORT: i64 = -1 |
functions
| 30 | func co_put(out: *u8, cap: i64, off: i64, src: *u8, n: i64) -> i64 { |
| 42 | func cors_allow_origin(out: *u8, cap: i64, off: i64, |
| 55 | func cors_allow_methods(out: *u8, cap: i64, off: i64, |
| 68 | func cors_allow_headers(out: *u8, cap: i64, off: i64, |
| 81 | func cors_expose_headers(out: *u8, cap: i64, off: i64,
calls 1: co_put |
| 94 | func cors_allow_credentials(out: *u8, cap: i64, off: i64) -> i64 {
calls 1: co_put |
| 102 | func cors_max_age(out: *u8, cap: i64, off: i64, seconds: i64) -> i64 { |
| 135 | func cors_permissive(out: *u8, cap: i64, off: i64) -> i64 { |
| 150 | func main() -> i64 { |