diff options
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 @@ | |||
| 1 | #define EPOLL | ||
| 2 | #define HTTPSERVER_IMPL | ||
| 3 | #include "httpserver.h" | ||
| 4 | |||
| 5 | #define SERVER_PORT 6970 | ||
| 6 | #define RESPONSE "default response" | ||
| 7 | |||
| 8 | void handle_request(struct http_request_s* request) { | ||
| 9 | http_string_t url = http_request_target(request); | ||
| 10 | |||
| 11 | printf("%s\n", url.buf); | ||
| 12 | |||
| 13 | struct http_response_s* response = http_response_init(); | ||
| 14 | http_response_status(response, 200); | ||
| 15 | http_response_header(response, "Content-Type", "text/html"); | ||
| 16 | http_response_body(response, RESPONSE, sizeof(RESPONSE) - 1); | ||
| 17 | http_respond(request, response); | ||
| 18 | } | ||
| 19 | |||
| 20 | int main() { | ||
| 21 | printf("> starting server on %d\n", SERVER_PORT); | ||
| 22 | |||
| 23 | struct http_server_s* server = http_server_init(SERVER_PORT, handle_request); | ||
| 24 | http_server_listen(server); | ||
| 25 | } | ||
