|
cwist
Modern C web framework with libttak runtime
|
HTTP request multiplexer (router). More...
#include <cwist/net/http/http.h>#include <cwist/sys/app/app.h>#include <cwist/core/sstring/sstring.h>#include <stdint.h>

Go to the source code of this file.
Classes | |
| struct | cwist_mux_middleware_node |
| struct | cwist_mux_route |
| struct | cwist_mux_router |
| struct | cwist_mux_group |
HTTP request multiplexer (router).
Definition in file mux.h.
| typedef void(* cwist_http_handler_func) (cwist_http_request *req, cwist_http_response *res) |
| cwist_mux_route * cwist_mux_find_route | ( | cwist_mux_router * | router, |
| cwist_http_method_t | method, | ||
| const char * | path | ||
| ) |
Find a matching route.
Find a matching route.
| router | Router whose exact and parametric routes are searched. |
| method | HTTP method to match. |
| path | Request path to resolve; NULL is treated as the root. |
Definition at line 325 of file mux.c.
References cwist_mux_route::bucket_next, cwist_mux_router::buckets, cap, cwist_query_map_destroy(), and cwist_mux_router::param_routes.
| cwist_mux_group * cwist_mux_group_create | ( | cwist_mux_router * | router, |
| const char * | prefix | ||
| ) |
Create a route group with a path prefix.
Create a route group with a path prefix.
| router | Router that will own the routes registered through the group. |
| prefix | Path prefix prepended to every route path registered on the group. |
Definition at line 361 of file mux.c.
References cap, cwist_alloc(), cwist_free(), and cwist_mux_group::router.
| void cwist_mux_group_destroy | ( | cwist_mux_group * | group | ) |
Destroy a route group.
Destroy a route group.
| group | Group to destroy. NULL is ignored. |
Definition at line 381 of file mux.c.
References cap, and cwist_free().
| void cwist_mux_group_handle | ( | cwist_mux_group * | group, |
| cwist_http_method_t | method, | ||
| const char * | path, | ||
| cwist_http_handler_func | handler | ||
| ) |
Register a handler inside a group.
Register a handler inside a group.
| group | Group supplying the path prefix and target router. |
| method | HTTP method to match. |
| path | Route path relative to the group prefix; the two are concatenated verbatim. |
| handler | Callback to invoke for a matching request. |
Definition at line 396 of file mux.c.
References cap, cwist_alloc(), CWIST_DEFER_FREE, and cwist_mux_handle().
| void cwist_mux_handle | ( | cwist_mux_router * | router, |
| cwist_http_method_t | method, | ||
| const char * | path, | ||
| cwist_http_handler_func | handler | ||
| ) |
Register a route handler.
Register a route handler.
| router | Router that will own the route metadata. |
| method | HTTP method to match. |
| path | Exact request path to dispatch. |
| handler | Callback to invoke for a matching request. |
Definition at line 160 of file mux.c.
Referenced by cwist_mux_group_handle().
| void cwist_mux_route_use | ( | cwist_mux_route * | route, |
| cwist_middleware_func | mw | ||
| ) |
Attach middleware to a specific route.
Attach middleware to a specific route.
| route | Route to attach the middleware to. NULL is ignored. |
| mw | Middleware function to prepend to the route's chain. NULL is ignored. |
Definition at line 418 of file mux.c.
References cap, cwist_alloc(), cwist_mux_middleware_node::func, and cwist_mux_middleware_node::next.
| cwist_mux_router * cwist_mux_router_create | ( | void | ) |
| void cwist_mux_router_destroy | ( | cwist_mux_router * | router | ) |
| bool cwist_mux_serve | ( | cwist_mux_router * | router, |
| cwist_http_request * | req, | ||
| cwist_http_response * | res | ||
| ) |
Dispatches an HTTP request through the router.
Dispatches an HTTP request through the router.
Dispatch a request.
| router | Router containing registered exact-match handlers. |
| req | Parsed HTTP request with method and path information. |
| res | HTTP response object passed through to the matched handler. |