http-server.h (1124B)
1 #ifndef __FINWO_HTTP_SERVER_H__ 2 #define __FINWO_HTTP_SERVER_H__ 3 4 #include <stdbool.h> 5 #include <stdint.h> 6 7 struct http_server_reqdata { 8 struct fnet_t *connection; // From the underlaying connection library 9 struct http_parser_pair *reqres; // The request/response pair 10 struct http_server_events *evs; 11 void *udata; 12 }; 13 14 struct http_server_opts { 15 struct http_server_events *evs; 16 char *addr; 17 uint16_t port; 18 void *udata; 19 bool shutdown; 20 struct fnet_t *listen_connection; 21 }; 22 23 struct http_server_events { 24 void (*serving)(char *addrs, uint16_t port, void *udata); 25 void (*close)(struct http_server_reqdata *reqdata); 26 void (*notFound)(struct http_server_reqdata *reqdata); 27 void (*tick)(void *udata); 28 }; 29 30 void http_server_main(struct http_server_opts *opts); 31 void http_server_response_send(struct http_server_reqdata *reqdata, bool close); 32 void http_server_route(const char *method, const char *path, void (*fn)(struct http_server_reqdata*)); 33 34 #endif // __FINWO_HTTP_SERVER_H__