Lua template: Improve and optimize

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao committed 2017-12-09 16:50:23 +08:00
1 parent 93705e0853
commit 90f38a6694
1 file changed
+6 -2
+6 -2
View File
@@ -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;
}