From 90f38a66942426066dfc870172fe33b5f5ea0e11 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Sat, 9 Dec 2017 16:50:23 +0800 Subject: [PATCH] Lua template: Improve and optimize Signed-off-by: Jianhui Zhao --- src/template.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/template.c b/src/template.c index b7550b2..3411fe9 100755 --- a/src/template.c +++ b/src/template.c @@ -579,9 +579,13 @@ void uh_template(struct uh_connection *con) int i; strcpy(path, con->srv->docroot); - strncat(path, con->req.path.at, con->req.path.len); - if (stat(path, &st) < 0) { + if (con->req.path.len == 1 && con->req.path.at[0] == '/') + strncat(path, "/index.html", 11); + else + strncat(path, con->req.path.at, con->req.path.len); + + if (stat(path, &st) < 0 || !S_ISREG(st.st_mode)) { uh_send_error(con, HTTP_STATUS_NOT_FOUND, NULL); return; }