94 const char *path,
size_t path_len,
KlBodyReader *(* KlBodyReaderFactory)(KlAllocator *alloc, const KlRequest *req, void *user_data)
Factory creates a body reader for a given request.
Definition body_reader.h:34
int kl_router_match(KlRouter *r, const char *method, size_t method_len, const char *path, size_t path_len, KlRoute **matched, KlParam *params, int *num_params)
Match a request against registered routes. HEAD requests automatically fall back to GET routes.
int kl_router_use_post(KlRouter *r, const char *method, const char *pattern, KlMiddleware fn, void *user_data)
Register post-body middleware that runs after body reading.
int kl_router_run_post_middleware(KlRouter *r, KlRequest *req, KlResponse *res)
Run all matching post-body middleware in registration order.
int kl_router_add(KlRouter *r, const char *method, const char *pattern, KlHandler handler, void *user_data, KlBodyReaderFactory body_reader)
Register a route. Pattern supports :param segments (e.g. "/users/:id").
void(* KlHandler)(KlRequest *req, KlResponse *res, void *user_data)
Route handler function.
Definition router.h:11
void kl_router_free(KlRouter *r)
Free router resources.
int kl_router_run_middleware(KlRouter *r, KlRequest *req, KlResponse *res)
Run all matching pre-body middleware in registration order.
int(* KlMiddleware)(KlRequest *req, KlResponse *res, void *user_data)
Middleware function signature.
Definition router.h:18
int kl_router_init(KlRouter *r, KlAllocator *alloc)
Initialize a router with an empty route table.
int kl_router_use(KlRouter *r, const char *method, const char *pattern, KlMiddleware fn, void *user_data)
Register pre-body middleware that runs before body reading.
Bring-your-own allocator vtable.
Definition allocator.h:12
size_t pattern_len
Definition router.h:37
void * user_data
Definition router.h:39
size_t method_len
Definition router.h:36
const char * method
Definition router.h:34
KlMiddleware fn
Definition router.h:38
const char * pattern
Definition router.h:35
const char * pattern
Definition router.h:24
KlWsServerConfig * ws_config
Definition router.h:30
size_t pattern_len
Definition router.h:26
const char * method
Definition router.h:23
size_t method_len
Definition router.h:25
void * user_data
Definition router.h:28
KlBodyReaderFactory body_reader
Definition router.h:29
KlHandler handler
Definition router.h:27
int post_mw_count
Definition router.h:52
int capacity
Definition router.h:45
KlRoute * routes
Definition router.h:43
KlMiddlewareEntry * middleware
Definition router.h:47
KlMiddlewareEntry * post_middleware
Definition router.h:51
int mw_count
Definition router.h:48
int count
Definition router.h:44
int mw_capacity
Definition router.h:49
KlAllocator * alloc
Definition router.h:55
int post_mw_capacity
Definition router.h:53
Definition websocket_server.h:34