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);