[hackers] [quark][PATCH] Add DEFAULT_MIME_TYPE macro

From: Spenser Truex <truex_AT_equwal.com>
Date: Tue, 20 Jun 2023 16:49:38 -0300

Set the default mime type. It can be helpful for a static HTTP site so
page names like site.com/page work rather than site.com/page.html

Of course, any static material must now be explicitly whitelisted as
application/octet-stream, so there is a trade-off when doing it this
way.
---
 config.def.h | 2 ++
 http.c       | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h
index 56f62aa..989f718 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -3,6 +3,7 @@
 #define BUFFER_SIZE 4096
 #define FIELD_MAX   200
+#define DEFAULT_MIME_TYPE "application/octet-stream"
 /* mime-types */
 static const struct {
_AT_@ -37,3 +38,4 @@ static const struct {
 };
 #endif /* CONFIG_H */
+
diff --git a/http.c b/http.c
index 36f8b1c..af67b82 100644
--- a/http.c
+++ b/http.c
_AT_@ -959,7 +959,7 @@ http_prepare_response(const struct request *req, struct response *res,
 	}
 	/* mime */
-	mime = "application/octet-stream";
+	mime = DEFAULT_MIME_TYPE;
 	if ((p = strrchr(res->internal_path, '.'))) {
 		for (i = 0; i < LEN(mimes); i++) {
 			if (!strcmp(mimes[i].ext, p + 1)) {
_AT_@ -1044,3 +1044,4 @@ http_prepare_error_response(const struct request *req,
 		}
 	}
 }
+
-- 
2.39.3

Received on Tue Jun 20 2023 - 21:49:38 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 20 2023 - 22:00:40 CEST