#ifndef HTTPSERVER_H #define HTTPSERVER_H #include #include #include #ifdef __cplusplus extern "C" { #endif typedef struct httpserver httpserver_t; typedef struct httpserver_conn httpserver_conn_t; typedef void (*httpserver_handler_t)(httpserver_conn_t *conn, const char *path, const char *query); typedef void (*httpserver_ws_open_t)(httpserver_conn_t *ws); typedef void (*httpserver_ws_msg_t)(httpserver_conn_t *ws, const uint8_t *data, size_t len, bool text); typedef void (*httpserver_ws_close_t)(httpserver_conn_t *ws); httpserver_t *httpserver_create(void); void httpserver_route(httpserver_t *s, const char *method, const char *path, httpserver_handler_t fn); void httpserver_websocket(httpserver_t *s, const char *path, httpserver_ws_open_t on_open, httpserver_ws_msg_t on_msg, httpserver_ws_close_t on_close); bool httpserver_listen(httpserver_t *s, uint16_t port); void httpserver_send(httpserver_conn_t *conn, int status, const char *content_type, const void *body, size_t body_len); /* Stream a large const body (no copy of entire file into conn buffer). * content_encoding may be NULL, or e.g. "gzip". */ void httpserver_send_static(httpserver_conn_t *conn, int status, const char *content_type, const uint8_t *body, size_t body_len, const char *content_encoding); void httpserver_send_html(httpserver_conn_t *conn, const char *html); /* POST/PUT body after headers (points into connection buffer). */ const char *httpserver_request_body(httpserver_conn_t *conn, size_t *len_out); bool httpserver_ws_send(httpserver_conn_t *ws, const void *data, size_t len, bool text); void httpserver_ws_broadcast(httpserver_t *s, const void *data, size_t len, bool text); httpserver_t *httpserver_conn_server(httpserver_conn_t *conn); #ifdef __cplusplus } #endif #endif