[hackers] [quark][PATCH] Fix for sending HTTP response status 304

From: Rainer Holzner <rholzner_AT_web.de>
Date: Wed, 22 Apr 2020 20:46:30 +0200

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.
---
 http.c | 1 +
 resp.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/http.c b/http.c
index efc4136..249c168 100644
--- a/http.c
+++ b/http.c
_AT_@ -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;
 		}
 	}
diff --git a/resp.c b/resp.c
index fbd8d5b..1716605 100644
--- a/resp.c
+++ b/resp.c
_AT_@ -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;
--
2.20.1
Received on Wed Apr 22 2020 - 20:46:30 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 22 2020 - 20:48:38 CEST