|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
Main Request Context — holds all state for the current HTTP request/response cycle. More...
#include <context_internal.h>

Data Fields | |
| int | handler_index |
| csilk_handler_t * | handlers |
| int | aborted |
| jmp_buf | jump_buffer |
| int | has_jump_buffer |
| csilk_arena_t * | arena |
| csilk_request_t | request |
| csilk_response_t | response |
| csilk_param_t | params [CSILK_MAX_PARAMS] |
| int | params_count |
| int | is_websocket |
| int | is_sse |
| void(* | on_ws_message )(csilk_ctx_t *c, const uint8_t *payload, size_t len, int opcode) |
| void(* | on_ws_send )(csilk_ctx_t *c, const uint8_t *payload, size_t len, int opcode) |
| csilk_storage_driver_t * | storage_driver |
| csilk_crypto_driver_t * | crypto_driver |
| csilk_cipher_driver_t * | cipher_driver |
| csilk_storage_item_t * | storage_head |
| struct csilk_server_s * | server |
| int32_t | stream_id |
| struct csilk_ctx_s * | next_stream |
| void * | _internal_client |
| uv_work_t | work_req |
| int | is_async |
| int | response_started |
| int | file_fd |
| size_t | file_offset |
| size_t | file_size |
| csilk_method_handler_t * | current_handler |
| char | request_id [37] |
Main Request Context — holds all state for the current HTTP request/response cycle.
Forward declaration of the request context (defined in csilk.h).
Opaque request context type. Created per-request by the server and passed to every handler and middleware. Carries the request, response, path parameters, arena allocator, storage, and connection state (WebSocket/SSE). Not thread-safe — access only from the libuv loop thread that owns the connection.
on_connection().csilk_ctx_cleanup() is called after each request completes, which resets arena memory, clears headers/params/body, and resets flags. The underlying TCP connection and SSL session are preserved.A single context is NEVER accessed from multiple threads simultaneously. The libuv event loop ensures serialized access per connection. Async operations (uv_queue_work) run on the thread pool but access to the context is synchronized via the libuv main-loop callback pattern.
| void* csilk_ctx_t::_internal_client |
Opaque pointer to the internal csilk_client_t. MUST NOT be used directly by handlers. Used internally by _csilk_send_data() to route data through TLS or raw TCP.
| int csilk_ctx_t::aborted |
Non-zero if handler execution was aborted via csilk_abort(). Subsequent csilk_next() calls are no-ops.
| csilk_arena_t* csilk_ctx_t::arena |
Request-scoped arena allocator. Memory is reset between requests. All short-lived allocations (headers, param values, storage items) are served from this arena.
| csilk_cipher_driver_t* csilk_ctx_t::cipher_driver |
Optional pluggable cipher backend for AES-256-GCM encrypt/decrypt, RSA-OAEP encrypt/decrypt, RSA-PSS sign/verify, and RSA-2048 key generation.
| csilk_crypto_driver_t* csilk_ctx_t::crypto_driver |
Optional pluggable crypto backend for HMAC, UUID generation, SHA256. Defaults to OpenSSL-based software implementation.
| csilk_method_handler_t* csilk_ctx_t::current_handler |
OpenAPI spec generation — tracks the current method handler's metadata Pointer to the method handler entry for the matched route (NULL if unmatched). Used by csilk_bind_reflect() and csilk_json_reflect() to infer input/output type names from route metadata.
| int csilk_ctx_t::file_fd |
File descriptor of the file being sent via sendfile(). -1 if not in use. Set by static file middleware for large file responses.
| size_t csilk_ctx_t::file_offset |
Byte offset into the file where sendfile should start reading (for partial/range requests).
| size_t csilk_ctx_t::file_size |
Total number of bytes to send from the file.
| int csilk_ctx_t::handler_index |
Index of the current handler in the chain; starts at -1 (before first handler).
| csilk_handler_t* csilk_ctx_t::handlers |
NULL-terminated array of handler function pointers for the matched route.
| int csilk_ctx_t::has_jump_buffer |
Non-zero if jump_buffer has been initialized and is safe to longjmp to. Guards against longjmp on uninitialized context.
| int csilk_ctx_t::is_async |
Non-zero if the response will be sent asynchronously (framework skips auto-send after handler chain returns). Set by csilk_response_write() for streaming responses or explicitly by csilk_set_async().
| int csilk_ctx_t::is_sse |
Non-zero if the connection is being used for Server-Sent Events streaming. When set, the framework does not auto-send the response after the handler returns.
| int csilk_ctx_t::is_websocket |
Non-zero if the connection has been upgraded to WebSocket (set by csilk_ws_handshake). When set, data frames are dispatched to on_ws_message instead of being parsed as HTTP.
| jmp_buf csilk_ctx_t::jump_buffer |
setjmp buffer for error recovery (used by panic/recovery middleware via longjmp).
| struct csilk_ctx_s* csilk_ctx_t::next_stream |
Linked list of active multiplexed contexts for a single client.
| void(* csilk_ctx_t::on_ws_message) (csilk_ctx_t *c, const uint8_t *payload, size_t len, int opcode) |
Callback invoked for each incoming WebSocket data frame. Set via csilk_set_on_ws_message(). Receives the context, unmasked payload, payload length, and opcode (0x1=text, 0x2=binary).
| void(* csilk_ctx_t::on_ws_send) (csilk_ctx_t *c, const uint8_t *payload, size_t len, int opcode) |
Callback invoked for each outgoing WebSocket data frame (for testing).
| csilk_param_t csilk_ctx_t::params[CSILK_MAX_PARAMS] |
URL path parameters captured during routing (key/value pairs). Populated by the router when matching parameterized routes like "/users/:id".
| int csilk_ctx_t::params_count |
Number of path parameters currently in params[] array.
| csilk_request_t csilk_ctx_t::request |
Parsed HTTP request data (method, path, headers, body, query params, form params). Populated by the llhttp-based HTTP parser.
| char csilk_ctx_t::request_id[37] |
Per-request unique identifier (UUID v4 string, 36 chars + null).
| csilk_response_t csilk_ctx_t::response |
HTTP response data (status, headers, body) to be sent to the client. Set by handler functions like csilk_string(), csilk_json(), etc.
| int csilk_ctx_t::response_started |
Non-zero if chunked response headers have already been sent to the client. Used by csilk_response_write() to avoid sending headers multiple times in streaming mode.
| struct csilk_server_s* csilk_ctx_t::server |
Pointer to the owning server instance.
| csilk_storage_driver_t* csilk_ctx_t::storage_driver |
Optional pluggable storage backend for csilk_set()/csilk_get(). When set, takes precedence over the internal linked-list storage. Set per-server and propagated to all contexts.
| csilk_storage_item_t* csilk_ctx_t::storage_head |
Head of the linked list for simple arena-backed key-value storage. Managed by csilk_set()/csilk_get() when no storage_driver is set.
| int32_t csilk_ctx_t::stream_id |
HTTP/2 Stream ID. 0 for HTTP/1.1 connections.
| uv_work_t csilk_ctx_t::work_req |
libuv work request structure for offloading async operations to the thread pool. Used by csilk_ai_chat_async() and other async handlers.