summaryrefslogtreecommitdiff
path: root/plugins/static/static.c
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-11-24 00:04:06 +0100
committertomsmeding <tom.smeding@gmail.com>2019-11-24 00:20:37 +0100
commit4216b9b8737b2bad9689b721b9e238456c0d4053 (patch)
tree5c42eba37db19f433524ac6a9c1da6ac6a8274f3 /plugins/static/static.c
parentc04fbe3df564c66b0f4261a4013ea349ab41418c (diff)
static: MIME type detection using 'xdg-mime' or 'file'
Diffstat (limited to 'plugins/static/static.c')
-rw-r--r--plugins/static/static.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/plugins/static/static.c b/plugins/static/static.c
index 0b39afe..61cd259 100644
--- a/plugins/static/static.c
+++ b/plugins/static/static.c
@@ -9,6 +9,7 @@
#include "plugin.h"
#include "util.h"
#include "buffer.h"
+#include "mime.h"
// Will only be set once in the registration function, which is before any threading is done
@@ -110,7 +111,10 @@ static Handler_ret_t connection_handler(int sock, Headers *headers) {
}
}
- buffer = build_response_headers("200 OK", "text/plain; charset=UTF-8", size);
+ const char *mimetype = mime_detect(path);
+ if (!mimetype) mimetype = "application/octet-stream";
+
+ buffer = build_response_headers("200 OK", mimetype, size);
if (!buffer_append_file(&buffer, path)) {
send_500(sock);
goto cleanup_return;
@@ -131,5 +135,7 @@ void plugin_register_yourself(register_callback_t callback) {
exit(1);
}
+ mime_init();
+
callback("static", &connection_handler);
}