http-server.c

Basic HTTP server and router in C
git clone git://git.finwo.net/lib/http-server.c
Log | Files | Refs | README

commit 5ee2a4c06b3834be5b6f06d3e5562bf5af9f0913
parent 0d1b64188eeb3140196da29d0592bafb20c94996
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Tue, 20 Feb 2024 22:38:41 +0100

No tag, only meta

Diffstat:
Mexample.c | 2+-
Msrc/http-server.c | 12++++++------
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/example.c b/example.c @@ -51,7 +51,7 @@ void route_get_hello(struct http_server_reqdata *reqdata) { void route_get_hello_named(struct http_server_reqdata *reqdata) { http_parser_header_set(reqdata->reqres->response, "Content-Type", "text/plain"); - const char *name = http_parser_tag_get(reqdata->reqres->request, "param:name"); + const char *name = http_parser_meta_get(reqdata->reqres->request, "param:name"); if (!name) name = "there"; reqdata->reqres->response->body = calloc(1, sizeof(struct buf)); diff --git a/src/http-server.c b/src/http-server.c @@ -83,7 +83,7 @@ static void _hs_onRequest(struct http_parser_event *ev) { // Tokenize the given path only once char **pathTokens = _hs_pathTokens(ev->request->path); char **routeTokens; - char *tag = calloc(strlen(ev->request->path), sizeof(char)); + char *meta = calloc(strlen(ev->request->path), sizeof(char)); int i; // Method/path matching @@ -122,14 +122,14 @@ static void _hs_onRequest(struct http_parser_event *ev) { // Here = route match - // Store url params as tag 'param:<name>' = 'path[i] + // Store url params as meta 'param:<name>' = 'path[i] i = 0; while((pathTokens[i] && routeTokens[i])) { if (routeTokens[i][0] != ':') { i++; continue; } - tag[0] = '\0'; - strcat(tag, "param:"); - strcat(tag, routeTokens[i]+1); - http_parser_tag_set(ev->request, tag, pathTokens[i]); + meta[0] = '\0'; + strcat(meta, "param:"); + strcat(meta, routeTokens[i]+1); + http_parser_meta_set(ev->request, meta, pathTokens[i]); i++; }