Fix sending of zero-size files

This commit is contained in:
Quentin Rameau 2017-07-22 01:36:56 +02:00 committed by Laslo Hunhold
parent 432898af71
commit b04ba86f9d

View file

@ -454,13 +454,13 @@ sendfile(int fd, char *name, struct request *r, struct stat *st, char *mime,
"Content-Length: %zu\r\n", "Content-Length: %zu\r\n",
s, status_str[s], timestamp(time(NULL), t1), s, status_str[s], timestamp(time(NULL), t1),
timestamp(st->st_mtim.tv_sec, t2), mime, timestamp(st->st_mtim.tv_sec, t2), mime,
upper - lower + (st->st_size > 0)) < 0) { upper - lower + 1) < 0) {
s = S_REQUEST_TIMEOUT; s = S_REQUEST_TIMEOUT;
goto cleanup; goto cleanup;
} }
if (range) { if (range) {
if (dprintf(fd, "Content-Range: bytes %zu-%zu/%zu\r\n", if (dprintf(fd, "Content-Range: bytes %zd-%zd/%zu\r\n",
lower, upper, st->st_size) < 0) { lower, upper + (upper < 0), st->st_size) < 0) {
s = S_REQUEST_TIMEOUT; s = S_REQUEST_TIMEOUT;
goto cleanup; goto cleanup;
} }