63 lines
2.7 KiB
Plaintext
63 lines
2.7 KiB
Plaintext
:title
|
|
Request
|
|
|
|
:sig
|
|
Request& context;
|
|
|
|
:see
|
|
>types
|
|
set_status
|
|
component
|
|
unit_render
|
|
ws_message
|
|
session_start
|
|
|
|
:content
|
|
`Request& context` is the request-local state object passed into UCE handlers. It carries incoming request data, response state, runtime metadata, and helper trees such as `context.cfg`, `context.props`, and `context.connection`.
|
|
|
|
## Core Fields
|
|
|
|
- `ServerState* server`: current server state
|
|
- `StringMap params`: FastCGI server parameters
|
|
- `StringMap get`: current request GET variables
|
|
- `StringMap post`: current request POST variables
|
|
- `StringMap cookies`: cookies sent by the browser
|
|
- `StringMap session`: current session data
|
|
- `String session_id`: session cookie ID
|
|
- `String session_name`: session cookie name
|
|
- `DTree cfg`: request-local configuration tree
|
|
- `DTree call`: invocation-local structured data for helpers such as component and unit calls
|
|
- `DTree connection`: broker-owned WebSocket connection state that persists across `WS(Request& context)` calls for the same socket
|
|
- `std::vector<UploadedFile> uploaded_files`: files uploaded in the current request
|
|
- `StringMap header`: headers to send back to the browser
|
|
- `StringList set_cookies`: cookies queued for the response
|
|
- `u64 random_seed`: current request noise seed
|
|
- `u64 random_index`: current request noise index position
|
|
|
|
## Response Control
|
|
|
|
`context.set_status(s32 code[, String reason])` sets the HTTP status line and updates `context.flags.status`. When `reason` is omitted, UCE uses a built-in standard reason phrase for common status codes.
|
|
|
|
## Flags And Stats
|
|
|
|
- `bool flags.log_request`: controls whether the request should be logged
|
|
- `u32 stats.bytes_written`
|
|
- `f64 stats.time_init`
|
|
- `f64 stats.time_start`
|
|
- `f64 stats.time_end`
|
|
|
|
## Common Usage Notes
|
|
|
|
- `context.cfg` is the usual place for structured configuration. Use `context.cfg.get_by_path("path/to/value")` for deep reads.
|
|
- `context.props` carries invocation data for component calls and unit calls.
|
|
- `context.in` carries the current request body, and for `WS(Request& context)` it is the current WebSocket message payload.
|
|
- `context.params["WS_..."]` exposes the current WebSocket message metadata directly on the request parameter map.
|
|
- `context.connection` is only meaningful for WebSocket traffic and persists for the lifetime of the connection.
|
|
|
|
`unit_render(String file_name, [Request& context])` invokes another UCE file using the current or supplied request context.
|
|
|
|
## Related Concepts
|
|
|
|
- PHP: `$_SERVER`, `$_GET`, `$_POST`, `$_COOKIE`, `$_SESSION`, `header()`, and `http_response_code()`
|
|
- JavaScript / Node.js: Express `req` and `res`, Fetch `Request`, `Headers`, cookies or session middleware, and per-connection state in WebSocket handlers
|