From 701a9be61238374a28a153e0e88f15764b239707 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 17 Feb 2018 08:42:27 +1000 Subject: [PATCH] forgot to get mime type when downloading files --- src/www.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/www.c b/src/www.c index 783bc3f..18d65d6 100644 --- a/src/www.c +++ b/src/www.c @@ -895,11 +895,29 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url if (conf.file_directories[file_dir]->display_on_web) { // send file filename = www_files_get_from_area(file_dir, file_sub, filen); + 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); + } free(filen); if (filename != NULL) { if (stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { fno = open(filename, O_RDONLY); if (fno != -1) { + + response = MHD_create_response_from_fd(s.st_size, fno); MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime); sprintf(buffer, "%ld", s.st_size);