feat: provide access to key segments from step
This commit is contained in:
parent
e29e02ff85
commit
9fa009ccf4
6 changed files with 51 additions and 11 deletions
|
|
@ -42,7 +42,6 @@ void lnm_http_loop_ctx_reset(lnm_http_loop_ctx *ctx) {
|
|||
lnm_http_req_reset(&ctx->req);
|
||||
lnm_http_res_reset(&ctx->res);
|
||||
|
||||
ctx->route = NULL;
|
||||
ctx->cur_step = NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,13 +58,10 @@ void lnm_http_loop_process_route(lnm_http_conn *conn) {
|
|||
lnm_http_loop_ctx *ctx = conn->ctx;
|
||||
const lnm_http_loop_gctx *gctx = ctx->g;
|
||||
|
||||
lnm_http_route_match match;
|
||||
|
||||
switch (lnm_http_router_route(&match, gctx->router, ctx->req.method,
|
||||
switch (lnm_http_router_route(&ctx->match, gctx->router, ctx->req.method,
|
||||
ctx->req.buf.s + ctx->req.path.o)) {
|
||||
case lnm_http_route_err_match:
|
||||
ctx->route = match.route;
|
||||
ctx->cur_step = match.route->step;
|
||||
ctx->cur_step = ctx->match.route->step;
|
||||
ctx->state = lnm_http_loop_state_parse_headers;
|
||||
break;
|
||||
case lnm_http_route_err_unknown_method:
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ lnm_err lnm_http_router_add(lnm_http_route **out, lnm_http_router *http_router,
|
|||
|
||||
switch (c) {
|
||||
case ':': {
|
||||
const char *next_slash_ptr = strchr(path, '/');
|
||||
const char *next_slash_ptr = strchr(path + 1, '/');
|
||||
const char *new_path =
|
||||
next_slash_ptr == NULL ? strchr(path, '\0') : next_slash_ptr;
|
||||
size_t key_len = new_path - path - 1;
|
||||
next_slash_ptr == NULL ? strchr(path + 1, '\0') : next_slash_ptr;
|
||||
size_t key_len = new_path - (path + 1);
|
||||
|
||||
if (key_len == 0) {
|
||||
res = lnm_err_invalid_route;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue