From 245a12a610c235478a1370196b0a5f6e89828480 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 23 May 2020 19:24:07 +0200 Subject: nicer index list, inspired by nginx --- hittpd.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/hittpd.c b/hittpd.c index a9ead14..1f943de 100644 --- a/hittpd.c +++ b/hittpd.c @@ -609,16 +609,20 @@ on_message_complete(http_parser *p) { goto file; } - close(stream_fd); - data->stream_fd = -1; - if (path[strlen(path)-1] != '/') { + close(stream_fd); + data->stream_fd = -1; + send_dir_redirect(p); return 0; } - if (!show_index) + if (!show_index) { + close(stream_fd); + data->stream_fd = -1; + return send_error(p, 403, "Forbidden"); + } char *buf; size_t len; @@ -633,32 +637,53 @@ on_message_complete(http_parser *p) { fprintf(stream, "" "

Index of "); print_htmlencoded(stream, path); - fprintf(stream, "

\n\n"); + fprintf(stream, "\n
\n"); fclose(stream); + close(stream_fd); + data->stream_fd = -1; + data->buf = buf; data->first = 0; data->last = len; -- cgit 1.4.1