From 66dee85d1fbfe7fecdd37503389ad467c3ccfb81 Mon Sep 17 00:00:00 2001 From: spl3g Date: Fri, 21 Mar 2025 14:37:04 +0300 Subject: Add global middleware support --- lib/http.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/http.h') diff --git a/lib/http.h b/lib/http.h index 2cfa9eb..0657095 100644 --- a/lib/http.h +++ b/lib/http.h @@ -101,13 +101,18 @@ struct handler_da { size_t cap; }; +typedef struct { + http_middleware *start; + http_middleware *end; +} http_global_middleware; + struct server { size_t sockfd; struct sockaddr *addr; arena *arena; handler_da handlers; context global_ctx; - http_middleware *global_middleware; + http_global_middleware *global_middleware; }; typedef enum { @@ -163,8 +168,9 @@ void http_send_body(struct request req, const_string body); int init_server(arena *arena, struct server *serv, char *addr, char *port); int listen_and_serve(struct server *serv); -handler *handle_path(struct server *serv, const_string method, const_string path, handler_func handler); +handler *http_handle_path(struct server *serv, const_string method, const_string path, handler_func handler); +void http_register_global_middleware(struct server *hand, http_middleware_func func); void http_register_handler_middleware(arena *arena, handler *hand, http_middleware_func func); #endif // HTTP_H_ -- cgit v1.2.3