Signature
Request& context
Request& context is the request-local state object passed into every UCE handler:
It is the main bridge between the runtime and page code. It contains incoming request data, response state, output buffers, per-request scratch trees, session/cookie state, WebSocket metadata, and runtime diagnostics.
Handler Lifetime
A fresh Request is created for each HTTP/CLI/custom-server request. Component and unit calls normally share that same object, so state placed on context.call, context.header, context.session, or context.cfg is visible to later components in the same request.
For WebSockets, each incoming message is delivered as its own Request, but context.connection points at broker-owned per-socket state that persists for the lifetime of that WebSocket connection.
ONCE(Request& context) hooks run once per request, per resolved unit file, before the first RENDER, COMPONENT, CLI, or matching entrypoint from that unit.
Incoming Request Maps
context.params — server/runtime parameters
Type: StringMap
This is the low-level parameter map from FastCGI/direct HTTP plus UCE-populated convenience fields. It is closest to PHP $_SERVER.
Common CGI/FastCGI-style keys include:
REQUEST_METHOD:GET,POST, etc.REQUEST_URI: raw request URI where availableDOCUMENT_URI: normalized request path where availableSCRIPT_NAME: script path where availableSCRIPT_FILENAME: resolved filesystem path of the active UCE unitQUERY_STRING: raw query stringDOCUMENT_ROOT: web root used by the frontend/backendCONTENT_TYPE: request body content typeCONTENT_LENGTH: request body lengthHTTP_COOKIE: raw cookie headerHTTP_HOST,HTTP_USER_AGENT,HTTP_ACCEPT, and otherHTTP_...headers supplied by the frontend
UCE also populates convenience route/link fields before handlers run:
SCRIPT_URL: canonical script URL;/index.uceis collapsed to the containing directory URLBASE_URL: canonical directory URL for the scriptROUTE_PATH: sanitized first keyless query-string segment, defaulting toindexwhen no route was supplied; empty when unsafe input was rejectedROUTE_PAGE: first segment ofROUTE_PATHROUTE_PATH_RAW: normalized but untrusted route input, for diagnostics onlyROUTE_VALID:1when route input is safe,0when the supplied route was rejected
See request_context_params, request_script_url, request_base_url, request_query_path, request_query_route, and route_path_sanitize.
context.get
Type: StringMap
Parsed query-string key/value parameters. This is populated from context.params["QUERY_STRING"] with parse_query().
For front-controller route URLs such as /?dashboard&theme=dark, the keyless dashboard segment is represented by sanitized ROUTE_PATH; named parameters such as theme=dark are available in context.get.
context.post
Type: StringMap
Parsed request body parameters for ordinary POST requests. URL-encoded bodies are parsed with parse_query(). Multipart form data is parsed with parse_multipart() and uploaded files are listed in context.uploaded_files.
context.cookies
Type: StringMap
Cookies sent by the client, parsed from HTTP_COOKIE. set_cookie() also updates this map after queuing a response cookie, so later code in the same request can observe the new value.
context.in
Type: String
Raw request body. For WebSocket handlers, this is the current message payload.
Use this for JSON APIs:
context.uploaded_files
Type: std::vector<UploadedFile>
Each UploadedFile contains:
file_name: original submitted filenametmp_name: temporary server-side upload pathsize: uploaded byte count
Use this with multipart form posts.
Session State
context.session
Type: StringMap
Session data loaded by session_start(). UCE does not load sessions automatically for every request; call session_start() before reading/writing session data.
At the end of a successful request, modified session data is saved automatically if a session is active.
context.session_id and context.session_name
The active session ID and cookie name after session_start().
Related helpers:
session_start()session_destroy()session_id_create()set_cookie()
Per-request Structured Trees
context.call
Type: DValue
General request-local scratch/configuration tree. It is shared by the page, components, and unit calls participating in the current request. Use it for app-level request state, fragments, router results, page type, page title, and other values that need to be read by later components.
Examples from front-controller style apps:
Prefer clear top-level names when state is app-wide (route, fragments) and nested app names only when the state is truly owned by that app (app/page_title, app/page_type).
context.cfg
Type: DValue
Request-local structured configuration. The runtime does not fill this with application config by default; application code may assign it during boot/setup:
This is separate from context.server->config, which is the runtime/server string config from /etc/uce/settings.cfg.
Use get_by_path() for non-mutating deep reads:
context.props
Type: DValue
Invocation-local props for component(), component_render(), and macro-style unit_call() entrypoints. During a component call, the runtime temporarily replaces context.props with the props passed to that component and restores the previous value after the call returns.
context.connection
Type: DValue
WebSocket connection-local state. Mutations persist across WS(Request& context) calls for the same socket.
Only meaningful for WebSocket handlers.
Response State
context.response_code
Type: String
The raw status line. Usually use context.set_status(...) instead of writing this directly.
context.header
Type: StringMap
Response headers to emit. Header names are case-sensitive as written.
context.set_cookies
Type: StringList
Queued Set-Cookie header lines. Prefer set_cookie() instead of editing this directly.
context.set_status(code[, reason])
Sets the HTTP response status and context.flags.status.
Related helpers:
redirect(url[, code])set_cookie(...)
Output Buffers
context.ob_stack and context.ob
Internal output-buffer stack. Most code should use helpers instead of touching these directly:
print(...)out(...)ob_start()ob_get()ob_get_close()ob_close()
Common capture pattern:
context.out and context.err
Runtime output/error artifacts used by some transports and failure paths. Normal page rendering should use print() / output buffers.
Request Flags
context.flags contains runtime booleans and the numeric status:
log_request: whether the request should be loggedis_finished: internal completion markerstatus: numeric HTTP status set byset_status()output_closed: internal transport stateparams_closed: internal transport stateinput_closed: internal transport state
Most page code only reads flags.status, if anything.
Request Stats
context.stats contains counters/timing for the request:
bytes_writtentime_inittime_starttime_endmem_highmem_allocinvoke_count
These are useful for diagnostics, demos, and runtime instrumentation.
Random / Noise State
random_seedrandom_index
Used by UCE noise/random helpers to provide request-local deterministic progression.
Related helpers include functions in the noise/hash area such as gen_int, gen_float, gen_noise64, and gen_sha1.
WebSocket Fields
In WS(Request& context), the runtime mirrors WebSocket metadata into context.params and context.resources.
Convenience context.params keys include:
WS_MESSAGEWS_CONNECTION_IDWS_SCOPEWS_CONNECTION_COUNTWS_OPCODEWS_MESSAGE_TYPEWS_DOCUMENT_URI
Prefer WebSocket helper functions where possible:
ws_message()ws_connection_id()ws_scope()ws_opcode()ws_is_binary()ws_connections()ws_connection_count()ws_send()ws_send_to()ws_close()
Use context.connection for per-socket structured state.
Runtime / Resource Fields
context.server
Pointer to server state. Useful mainly for low-level/runtime code. Runtime config lives at:
This is a StringMap, separate from app-owned context.cfg.
context.resources
Internal runtime resources and transport state. Includes sockets, MySQL handles, WebSocket state, current unit file, and parser buffers. Application code should normally use public helpers instead of editing this directly.
Notable fields:
is_websocketis_cliwebsocket_connection_idwebsocket_scopewebsocket_scope_connection_idscurrent_unit_file
Common Patterns
Minimal page
JSON endpoint
Redirect
Component props
Front-controller route
Or use runtime-populated params directly:
Example
print(context.params["REQUEST_URI"] != "" ? "request available\n" : "request available\n");
request available