Lua template: Improve and optimize

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-12-09 16:50:23 +08:00
parent 93705e0853
commit 90f38a6694
1 changed files with 6 additions and 2 deletions

View File

@ -579,9 +579,13 @@ void uh_template(struct uh_connection *con)
int i;
strcpy(path, con->srv->docroot);
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) {
if (stat(path, &st) < 0 || !S_ISREG(st.st_mode)) {
uh_send_error(con, HTTP_STATUS_NOT_FOUND, NULL);
return;
}