From 256aa800f73ad902e70e36c6f3af5c39cb79a3a6 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Tue, 23 Jan 2018 21:37:23 +1000 Subject: [PATCH] fix mimetype --- src/www.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/www.c b/src/www.c index 91e221b..d648900 100644 --- a/src/www.c +++ b/src/www.c @@ -830,6 +830,23 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url } else if (strncasecmp(url, "/files/", 7) == 0) { filename = www_decode_hash(&url[7]); if (filename != NULL) { + mime = NULL; + // get mimetype + for (i=strlen(filename);i>0;--i) { + if (filename[i] == '.') { + mime = www_get_mime_type(&filename[i+1]); + break; + } + if (filename[i] == '/') { + mime = www_get_mime_type(NULL); + break; + } + } + + if (mime = NULL) { + mime = www_get_mime_type(NULL); + } + if (stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { fno = open(filename, O_RDONLY); if (fno != -1) {