Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
request_id.c File Reference

Request ID middleware implementation. More...

#include <string.h>
#include "csilk/core/internal.h"
#include "csilk/csilk.h"
Include dependency graph for request_id.c:

Functions

void csilk_request_id_middleware (csilk_ctx_t *c)
 Request ID middleware handler.
 
void csilk_health_check_handler (csilk_ctx_t *c)
 Built-in Health Check handler (Liveness).
 
void csilk_ready_check_handler (csilk_ctx_t *c)
 Built-in Readiness Check handler (Readiness).
 

Detailed Description

Request ID middleware implementation.

Function Documentation

◆ csilk_health_check_handler()

void csilk_health_check_handler ( csilk_ctx_t *  c)

Built-in Health Check handler (Liveness).

Built-in Health Check handler. Returns a simple JSON response {"status": "up"}.

Provides a simple "shallow" check to verify that the server's event loop is alive and responsive. Returns a JSON response with status 200 OK.

Parameters
cThe request context. If NULL the function returns immediately.
Note
Used by load balancers and orchestrators for Liveness probes.

◆ csilk_ready_check_handler()

void csilk_ready_check_handler ( csilk_ctx_t *  c)

Built-in Readiness Check handler (Readiness).

Built-in Readiness Check handler. Performs deep health check (MQ, connections) and returns 200 or 503.

Performs a "deep" check of the server's health by inspecting critical subsystems. It checks:

  1. MQ Queue Depth: Returns unhealthy if the message queue is saturated.
  2. Active Connections: Returns unhealthy if the server is near its capacity.

Returns 200 OK if the server is ready to accept more traffic, or 503 Service Unavailable if any check fails.

Parameters
cThe request context. If NULL the function returns immediately.
Note
Used by load balancers and orchestrators for Readiness probes to decide whether to route traffic to this instance.

◆ csilk_request_id_middleware()

void csilk_request_id_middleware ( csilk_ctx_t *  c)

Request ID middleware handler.

Request ID middleware. Generates a unique ID for each request and sets X-Request-Id header.

Ensures every request has a unique UUID v4 identifier. If the request context does not already have an ID (c->request_id is empty), a new UUID is generated via _csilk_generate_uuid(). The identifier is then set as the "X-Request-Id" response header and propagated to the thread-local logger state for distributed tracing correlation.

Parameters
cThe request context. If NULL the function returns immediately.
Note
Should be registered as the very first middleware in the pipeline so all downstream handlers and log entries share the same request identifier.
Warning
The UUID generation uses whatever _csilk_generate_uuid() implements — ensure it provides sufficient entropy for your deployment.