feat(routing): make path segments easily accessible from request struct

This commit is contained in:
Jef Roosens 2024-02-25 21:50:51 +01:00
parent fbd41f7e4e
commit 3ae1b62dd0
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
6 changed files with 105 additions and 65 deletions

View file

@ -1,5 +1,6 @@
#include <unistd.h>
#include "lnm/http/req.h"
#include "lnm/log.h"
#include "lnm/loop.h"
#include "lnm/http/loop.h"
@ -16,8 +17,9 @@ void ctx_free(void *c_ctx) {}
lnm_http_step_err print_step(lnm_http_conn *conn) {
lnm_http_loop_ctx *ctx = conn->ctx;
const lnm_http_route_match_segment *seg = lnm_http_route_match_get(&ctx->match, "key");
lnm_linfo("main", "key: %.*s", seg->len, ctx->req.buf.s + ctx->req.path.o + seg->start);
const char *key;
size_t key_len = lnm_http_req_route_segment(&key, &ctx->req, "key") ;
lnm_linfo("main", "key: %.*s", key_len, key);
return lnm_http_step_err_done;
}