diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-03-11 22:32:56 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2025-03-11 22:32:56 +0100 |
| commit | 29fb1c172b2b235a6484f23f8d5b391f877e98eb (patch) | |
| tree | 7c8008a2c692af9104e0a9e91358779db99e7d28 /c-httpd/httpd.c | |
| parent | 68ac646c552980e8119e0a789b83ba82d0a594a4 (diff) | |
| download | probe-29fb1c172b2b235a6484f23f8d5b391f877e98eb.tar.gz | |
Added simple HTTPD server in C
Diffstat (limited to 'c-httpd/httpd.c')
| -rw-r--r-- | c-httpd/httpd.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/c-httpd/httpd.c b/c-httpd/httpd.c new file mode 100644 index 0000000..cb79df1 --- /dev/null +++ b/c-httpd/httpd.c @@ -0,0 +1,25 @@ +#define EPOLL +#define HTTPSERVER_IMPL +#include "httpserver.h" + +#define SERVER_PORT 6970 +#define RESPONSE "default response" + +void handle_request(struct http_request_s* request) { + http_string_t url = http_request_target(request); + + printf("%s\n", url.buf); + + struct http_response_s* response = http_response_init(); + http_response_status(response, 200); + http_response_header(response, "Content-Type", "text/html"); + http_response_body(response, RESPONSE, sizeof(RESPONSE) - 1); + http_respond(request, response); +} + +int main() { + printf("> starting server on %d\n", SERVER_PORT); + + struct http_server_s* server = http_server_init(SERVER_PORT, handle_request); + http_server_listen(server); +} |
