do not cache 404 responses

This commit is contained in:
hummypkg 2017-01-14 20:23:47 +00:00
parent 79d7558148
commit c90521b740
1 changed files with 13 additions and 7 deletions

20
main.c
View File

@ -317,16 +317,22 @@ send_file(int fd, char *file, char *type, int chunked, int size, int cache)
}
}
if ((ifd = open(file, O_RDONLY)) < 0)
{
/* Don't set caching for the 404 response. */
cache = 0;
if ((ifd = open("404.html", O_RDONLY)) < 0)
{
headers(fd, "text/plain", NULL, 0);
send_fd(fd, "Error opening %s\n", file);
return;
}
}
if (type)
headers(fd, type, NULL, cache);
if ((ifd = open(file, O_RDONLY)) < 0 &&
(ifd = open("404.html", O_RDONLY)) < 0)
{
send_fd(fd, "Error opening %s\n", file);
return;
}
fstat(ifd, &st);
if (size <= 0 || size > st.st_size)