#include #define port "8000" static void hello_action(struct uh_client *cl) { cl->send_header(cl, 200, "OK", -1); cl->append_header(cl, "Myheader", "Hello"); cl->header_end(cl); cl->chunk_printf(cl, "

Hello Libuhttpd %s

", UHTTPD_VERSION_STRING); cl->chunk_printf(cl, "

REMOTE_ADDR: %s

", cl->get_peer_addr(cl)); cl->chunk_printf(cl, "

PATH: %s

", cl->get_path(cl)); cl->chunk_printf(cl, "

QUERY: %s

", cl->get_query(cl)); cl->request_done(cl); } int main(int argc, char **argv) { struct uh_server *srv = NULL; uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING); uloop_init(); srv = uh_server_new("0.0.0.0", port); if (!srv) goto done; uh_log_debug("Listen on: *:%s", port); #if (UHTTPD_SSL_SUPPORT) if (srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0) goto done; #endif uh_add_action(srv, "/hello", hello_action); uloop_run(); done: uloop_done(); srv->free(srv); return 0; }