summaryrefslogtreecommitdiff
path: root/plugins/static/mime.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/static/mime.c')
-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;