C Collections

chttpserver · Section 3

chttpsvr_req_context

chttpsvr_req_context - read a value that a middleware attached to a request

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
void *chttpsvr_req_context(const chttpsvr_req *req, const void *key);

Returns the value that chttpsvr_req_set_context attached to req under
key.  Keys are compared by address and nothing else.  The values can
be read until the chain of the request returns; see
chttpsvr_req_set_context(3) for that lifetime.

req   The request.
key   The key, compared by address.

The value attached under key.  NULL when req or key is NULL, when no
value is attached under key, and also when the stored value is NULL.

Call it only on the thread that runs the chain of the request, and
only while that chain runs.  It takes no lock.

static const char trace_key;
 
const char *trace = chttpsvr_req_context(req, &trace_key);
if (trace) chttpsvr_resp_set_header(resp, "x-trace-id", trace);

chttpsvr_req_set_context(3), chttpsvr_use(3), chttpsvr_router_use(3)