feat(routing): multi-segment wildcard matches
This commit is contained in:
parent
3ae1b62dd0
commit
115bf74456
3 changed files with 94 additions and 15 deletions
|
|
@ -23,6 +23,25 @@ lnm_http_step_err print_step(lnm_http_conn *conn) {
|
|||
return lnm_http_step_err_done;
|
||||
}
|
||||
|
||||
lnm_http_step_err print_step2(lnm_http_conn *conn) {
|
||||
lnm_http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
const char *key;
|
||||
size_t key_len = lnm_http_req_route_segment(&key, &ctx->req, "key") ;
|
||||
lnm_linfo("main", "yuhh key: %.*s", key_len, key);
|
||||
return lnm_http_step_err_done;
|
||||
}
|
||||
|
||||
lnm_http_step_err print_step3(lnm_http_conn *conn) {
|
||||
lnm_http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
const char *key;
|
||||
size_t key_len = lnm_http_req_route_segment(&key, &ctx->req, "cool") ;
|
||||
lnm_linfo("main", "cool: %.*s", key_len, key);
|
||||
return lnm_http_step_err_done;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
lnm_http_loop *hl;
|
||||
|
||||
|
|
@ -34,8 +53,13 @@ int main() {
|
|||
lnm_http_router_init(&router);
|
||||
|
||||
lnm_http_route *route;
|
||||
lnm_http_router_add(&route, router, lnm_http_method_get, "/emma");
|
||||
lnm_http_router_add(&route, router, lnm_http_method_get, "/:key");
|
||||
lnm_http_route_step_append(route, print_step, false);
|
||||
lnm_http_router_add(&route, router, lnm_http_method_get, "/:key/two");
|
||||
lnm_http_route_step_append(route, print_step2, false);
|
||||
lnm_http_router_add(&route, router, lnm_http_method_get, "/*cool");
|
||||
lnm_http_route_step_append(route, print_step3, false);
|
||||
|
||||
lnm_http_loop_router_set(hl, router);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue