summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-11-24 00:19:52 +0100
committertomsmeding <tom.smeding@gmail.com>2019-11-24 00:20:39 +0100
commit7a5a4bbc1742cbd2492f6e9fcdb5c4aa65396371 (patch)
treebc5a194c41eb4b9a1aaacc02f14e469b8a7b5607
parent4216b9b8737b2bad9689b721b9e238456c0d4053 (diff)
static: Some filename based preset mimes, because 'file' doesn't have those
-rw-r--r--plugins/static/mime.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugins/static/mime.c b/plugins/static/mime.c
index 6be5078..e00588a 100644
--- a/plugins/static/mime.c
+++ b/plugins/static/mime.c
@@ -178,7 +178,31 @@ static char* mime_detect_perform(const char *path) {
return NULL;
}
+static const char* mime_detect_filename(const char *path) {
+ size_t len = strlen(path);
+ if (len == 0) return NULL;
+
+ size_t dotidx = len - 1;
+ while (dotidx > 0 && path[dotidx] != '.' && path[dotidx] != '/') dotidx--;
+ if (path[dotidx] == '/') return NULL;
+
+ const char *extension = path + dotidx + 1;
+
+ if (strcmp(extension, "html") == 0) return "text/html";
+ if (strcmp(extension, "htm") == 0) return "text/html";
+ if (strcmp(extension, "txt") == 0) return "text/plain";
+ if (strcmp(extension, "js") == 0) return "text/javascript";
+ if (strcmp(extension, "css") == 0) return "text/css";
+
+ return NULL;
+}
+
const char* mime_detect(const char *path) {
+ {
+ const char *typ_from_name = mime_detect_filename(path);
+ if (typ_from_name) return typ_from_name;
+ }
+
struct timespec now_mtime = get_file_mtime(path);
if (now_mtime.tv_sec < 0) return NULL;