1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-22 16:14:07 +00:00
zap/facil.io/examples/boiler_plate/src/http_service.c
2023-12-22 04:03:32 +01:00

25 lines
1,005 B
C

#include "fio_cli.h"
#include "main.h"
/* TODO: edit this function to handle HTTP data and answer Websocket requests.*/
static void on_http_request(http_s *h) {
/* set a response and send it (finnish vs. destroy). */
http_send_body(h, "Hello World!", 12);
}
/* starts a listeninng socket for HTTP connections. */
void initialize_http_service(void) {
/* listen for inncoming connections */
if (http_listen(fio_cli_get("-p"), fio_cli_get("-b"),
.on_request = on_http_request,
.max_body_size = fio_cli_get_i("-maxbd") * 1024 * 1024,
.ws_max_msg_size = fio_cli_get_i("-max-msg") * 1024,
.public_folder = fio_cli_get("-public"),
.log = fio_cli_get_bool("-log"),
.timeout = fio_cli_get_i("-keep-alive"),
.ws_timeout = fio_cli_get_i("-ping")) == -1) {
/* listen failed ?*/
perror("ERROR: facil couldn't initialize HTTP service (already running?)");
exit(1);
}
}