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 0a812dc90e46a415b5cad8426d825bd0c79527b5
parent c8537eb2a3787cee2b0cb4d4cb21c09e472bdb8c
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Fri, 17 Nov 2023 00:04:06 +0100

Make the example work with same-thread fnet again

Diffstat:
Mexample.c | 9+++++----
Msrc/http-server.c | 5+++++
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/example.c b/example.c @@ -26,6 +26,7 @@ void onTick(void *udata) { printf("Shutdown in %d second(s)\n", --countDown); if (countDown <= 0) { opts->shutdown = true; + fnet_shutdown(); return; } @@ -84,14 +85,14 @@ int main() { http_server_route("GET" , "/hello", route_get_hello); http_server_route("POST", "/port" , route_post_port); - // Launch network management thread - thd_thread thread; - thd_thread_detach(&thread, fnet_thread, NULL); + /* // Launch network management thread */ + /* thd_thread thread; */ + /* thd_thread_detach(&thread, fnet_thread, NULL); */ http_server_main(&opts); fnet_shutdown(); - thd_thread_join(&thread); + /* thd_thread_join(&thread); */ printf("Server has shut down\n"); } diff --git a/src/http-server.c b/src/http-server.c @@ -64,6 +64,11 @@ static void _hs_onRequest(struct http_parser_event *ev) { struct hs_route *route = registered_routes; struct hs_route *selected_route = NULL; + printf("Request detected: %s %s\n", + ev->request->method, + ev->request->path + ); + // Method/path matching, should be more intricate later (like /posts/:postId/comments) while(route) { if (