Fix for sending HTTP response status 304

Stop immediately after responding with status code 304 "Not Modified".
This also solves missing log output for status 304.

If there is an error while sending a file, try to clean up and close the
file.
This commit is contained in:
Rainer Holzner 2020-04-22 20:46:30 +02:00 committed by Laslo Hunhold
parent 9dda0028db
commit b7d0d6889d
No known key found for this signature in database
GPG key ID: 69576BD24CFCB980
2 changed files with 5 additions and 2 deletions

1
http.c
View file

@ -541,6 +541,7 @@ http_send_response(int fd, struct request *r)
timestamp(time(NULL), t)) < 0) {
return S_REQUEST_TIMEOUT;
}
return S_NOT_MODIFIED;
}
}

6
resp.c
View file

@ -216,14 +216,16 @@ resp_file(int fd, char *name, struct request *r, struct stat *st, char *mime,
while ((bread = fread(buf, 1, MIN(sizeof(buf),
(size_t)remaining), fp))) {
if (bread < 0) {
return S_INTERNAL_SERVER_ERROR;
s = S_INTERNAL_SERVER_ERROR;
goto cleanup;
}
remaining -= bread;
p = buf;
while (bread > 0) {
bwritten = write(fd, p, bread);
if (bwritten <= 0) {
return S_REQUEST_TIMEOUT;
s = S_REQUEST_TIMEOUT;
goto cleanup;
}
bread -= bwritten;
p += bwritten;