|  | @@ -202,7 +202,7 @@ typedef struct DIR {
 | 
	
		
			
				|  |  |      struct dirent  result;
 | 
	
		
			
				|  |  |  } DIR;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -#ifndef USE_IPV6 && defined(_WIN32)
 | 
	
		
			
				|  |  | +#if !defined(USE_IPV6) && defined(_WIN32)
 | 
	
		
			
				|  |  |  #ifndef HAVE_POLL
 | 
	
		
			
				|  |  |  struct pollfd {
 | 
	
		
			
				|  |  |      SOCKET fd;
 | 
	
	
		
			
				|  | @@ -2203,54 +2203,87 @@ static const struct {
 | 
	
		
			
				|  |  |      size_t ext_len;
 | 
	
		
			
				|  |  |      const char *mime_type;
 | 
	
		
			
				|  |  |  } builtin_mime_types[] = {
 | 
	
		
			
				|  |  | -    {".html", 5, "text/html"},
 | 
	
		
			
				|  |  | -    {".htm", 4, "text/html"},
 | 
	
		
			
				|  |  | -    {".shtm", 5, "text/html"},
 | 
	
		
			
				|  |  | -    {".shtml", 6, "text/html"},
 | 
	
		
			
				|  |  | -    {".css", 4, "text/css"},
 | 
	
		
			
				|  |  | -    {".js",  3, "application/x-javascript"},
 | 
	
		
			
				|  |  | -    {".ico", 4, "image/x-icon"},
 | 
	
		
			
				|  |  | -    {".gif", 4, "image/gif"},
 | 
	
		
			
				|  |  | -    {".jpg", 4, "image/jpeg"},
 | 
	
		
			
				|  |  | -    {".jpeg", 5, "image/jpeg"},
 | 
	
		
			
				|  |  | -    {".png", 4, "image/png"},
 | 
	
		
			
				|  |  | -    {".svg", 4, "image/svg+xml"},
 | 
	
		
			
				|  |  | -    {".txt", 4, "text/plain"},
 | 
	
		
			
				|  |  | +    // IANA registered MIME types (http://www.iana.org/assignments/media-types)
 | 
	
		
			
				|  |  | +    // application types
 | 
	
		
			
				|  |  | +    {".doc",     4, "application/msword"},
 | 
	
		
			
				|  |  | +    {".eps",     4, "application/postscript"},
 | 
	
		
			
				|  |  | +    {".exe",     4, "application/octet-stream"},
 | 
	
		
			
				|  |  | +    {".js",      3, "application/javascript"},
 | 
	
		
			
				|  |  | +    {".json",    5, "application/json"},
 | 
	
		
			
				|  |  | +    {".pdf",     4, "application/pdf"},
 | 
	
		
			
				|  |  | +    {".ps",      3, "application/postscript"},
 | 
	
		
			
				|  |  | +    {".rtf",     4, "application/rtf"},
 | 
	
		
			
				|  |  | +    {".xhtml",   6, "application/xhtml+xml"},
 | 
	
		
			
				|  |  | +    {".xsl",     4, "application/xml"},
 | 
	
		
			
				|  |  | +    {".xslt",    5, "application/xml"},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // audio
 | 
	
		
			
				|  |  | +    {".mp3",     4, "audio/mpeg"},
 | 
	
		
			
				|  |  | +    {".oga",     4, "audio/ogg"},
 | 
	
		
			
				|  |  | +    {".ogg",     4, "audio/ogg"},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // image
 | 
	
		
			
				|  |  | +    {".gif",     4, "image/gif"},
 | 
	
		
			
				|  |  | +    {".ief",     4, "image/ief"},
 | 
	
		
			
				|  |  | +    {".jpeg",    5, "image/jpeg"},
 | 
	
		
			
				|  |  | +    {".jpg",     4, "image/jpeg"},
 | 
	
		
			
				|  |  | +    {".jpm",     4, "image/jpm"},
 | 
	
		
			
				|  |  | +    {".jpx",     4, "image/jpx"},
 | 
	
		
			
				|  |  | +    {".png",     4, "image/png"},
 | 
	
		
			
				|  |  | +    {".svg",     4, "image/svg+xml"},
 | 
	
		
			
				|  |  | +    {".tif",     4, "image/tiff"},
 | 
	
		
			
				|  |  | +    {".tiff",    5, "image/tiff"},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // model
 | 
	
		
			
				|  |  | +    {".wrl",     4, "model/vrml"},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // text
 | 
	
		
			
				|  |  | +    {".css",     4, "text/css"},
 | 
	
		
			
				|  |  | +    {".csv",     4, "text/csv"},
 | 
	
		
			
				|  |  | +    {".htm",     4, "text/html"},
 | 
	
		
			
				|  |  | +    {".html",    5, "text/html"},
 | 
	
		
			
				|  |  | +    {".sgm",     4, "text/sgml"},
 | 
	
		
			
				|  |  | +    {".shtm",    5, "text/html"},
 | 
	
		
			
				|  |  | +    {".shtml",   6, "text/html"},
 | 
	
		
			
				|  |  | +    {".txt",     4, "text/plain"},
 | 
	
		
			
				|  |  | +    {".xml",     4, "text/xml"},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // video
 | 
	
		
			
				|  |  | +    {".mov",     4, "video/quicktime"},
 | 
	
		
			
				|  |  | +    {".mp4",     4, "video/mp4"},
 | 
	
		
			
				|  |  | +    {".mpeg",    5, "video/mpeg"},
 | 
	
		
			
				|  |  | +    {".mpg",     4, "video/mpeg"},
 | 
	
		
			
				|  |  | +    {".ogv",     4, "video/ogg"},
 | 
	
		
			
				|  |  | +    {".qt",      3, "video/quicktime"},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // not registered types (http://reference.sitepoint.com/html/mime-types-full, http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php, ..)
 | 
	
		
			
				|  |  | +    {".arj",     4, "application/x-arj-compressed"},
 | 
	
		
			
				|  |  | +    {".gz",      3, "application/x-gunzip"},
 | 
	
		
			
				|  |  | +    {".rar",     4, "application/x-arj-compressed"},
 | 
	
		
			
				|  |  | +    {".swf",     4, "application/x-shockwave-flash"},
 | 
	
		
			
				|  |  | +    {".tar",     4, "application/x-tar"},
 | 
	
		
			
				|  |  | +    {".tgz",     4, "application/x-tar-gz"},
 | 
	
		
			
				|  |  |      {".torrent", 8, "application/x-bittorrent"},
 | 
	
		
			
				|  |  | -    {".wav", 4, "audio/x-wav"},
 | 
	
		
			
				|  |  | -    {".mp3", 4, "audio/x-mp3"},
 | 
	
		
			
				|  |  | -    {".mid", 4, "audio/mid"},
 | 
	
		
			
				|  |  | -    {".m3u", 4, "audio/x-mpegurl"},
 | 
	
		
			
				|  |  | -    {".ogg", 4, "audio/ogg"},
 | 
	
		
			
				|  |  | -    {".ram", 4, "audio/x-pn-realaudio"},
 | 
	
		
			
				|  |  | -    {".xml", 4, "text/xml"},
 | 
	
		
			
				|  |  | -    {".json",  5, "text/json"},
 | 
	
		
			
				|  |  | -    {".xslt", 5, "application/xml"},
 | 
	
		
			
				|  |  | -    {".xsl", 4, "application/xml"},
 | 
	
		
			
				|  |  | -    {".ra",  3, "audio/x-pn-realaudio"},
 | 
	
		
			
				|  |  | -    {".doc", 4, "application/msword"},
 | 
	
		
			
				|  |  | -    {".exe", 4, "application/octet-stream"},
 | 
	
		
			
				|  |  | -    {".zip", 4, "application/x-zip-compressed"},
 | 
	
		
			
				|  |  | -    {".xls", 4, "application/excel"},
 | 
	
		
			
				|  |  | -    {".tgz", 4, "application/x-tar-gz"},
 | 
	
		
			
				|  |  | -    {".tar", 4, "application/x-tar"},
 | 
	
		
			
				|  |  | -    {".gz",  3, "application/x-gunzip"},
 | 
	
		
			
				|  |  | -    {".arj", 4, "application/x-arj-compressed"},
 | 
	
		
			
				|  |  | -    {".rar", 4, "application/x-arj-compressed"},
 | 
	
		
			
				|  |  | -    {".rtf", 4, "application/rtf"},
 | 
	
		
			
				|  |  | -    {".pdf", 4, "application/pdf"},
 | 
	
		
			
				|  |  | -    {".swf", 4, "application/x-shockwave-flash"},
 | 
	
		
			
				|  |  | -    {".mpg", 4, "video/mpeg"},
 | 
	
		
			
				|  |  | -    {".webm", 5, "video/webm"},
 | 
	
		
			
				|  |  | -    {".mpeg", 5, "video/mpeg"},
 | 
	
		
			
				|  |  | -    {".mov", 4, "video/quicktime"},
 | 
	
		
			
				|  |  | -    {".mp4", 4, "video/mp4"},
 | 
	
		
			
				|  |  | -    {".m4v", 4, "video/x-m4v"},
 | 
	
		
			
				|  |  | -    {".asf", 4, "video/x-ms-asf"},
 | 
	
		
			
				|  |  | -    {".avi", 4, "video/x-msvideo"},
 | 
	
		
			
				|  |  | -    {".bmp", 4, "image/bmp"},
 | 
	
		
			
				|  |  | -    {".ttf", 4, "application/x-font-ttf"},
 | 
	
		
			
				|  |  | -    {NULL,  0, NULL}
 | 
	
		
			
				|  |  | +    {".ppt",     4, "application/x-mspowerpoint"},
 | 
	
		
			
				|  |  | +    {".xls",     4, "application/x-msexcel"},
 | 
	
		
			
				|  |  | +    {".zip",     4, "application/x-zip-compressed"},
 | 
	
		
			
				|  |  | +    {".aac",     4, "audio/aac"}, // http://en.wikipedia.org/wiki/Advanced_Audio_Coding
 | 
	
		
			
				|  |  | +    {".aif",     4, "audio/x-aif"},
 | 
	
		
			
				|  |  | +    {".m3u",     4, "audio/x-mpegurl"},
 | 
	
		
			
				|  |  | +    {".mid",     4, "audio/x-midi"},
 | 
	
		
			
				|  |  | +    {".ra",      3, "audio/x-pn-realaudio"},
 | 
	
		
			
				|  |  | +    {".ram",     4, "audio/x-pn-realaudio"},
 | 
	
		
			
				|  |  | +    {".wav",     4, "audio/x-wav"},
 | 
	
		
			
				|  |  | +    {".bmp",     4, "image/bmp"},
 | 
	
		
			
				|  |  | +    {".ico",     4, "image/x-icon"},
 | 
	
		
			
				|  |  | +    {".pct",     4, "image/x-pct"},
 | 
	
		
			
				|  |  | +    {".pict",    5, "image/pict"},
 | 
	
		
			
				|  |  | +    {".rgb",     4, "image/x-rgb"},
 | 
	
		
			
				|  |  | +    {".webm",    5, "video/webm"}, // http://en.wikipedia.org/wiki/WebM
 | 
	
		
			
				|  |  | +    {".asf",     4, "video/x-ms-asf"},
 | 
	
		
			
				|  |  | +    {".avi",     4, "video/x-msvideo"},
 | 
	
		
			
				|  |  | +    {".m4v",     4, "video/x-m4v"},
 | 
	
		
			
				|  |  | +    {NULL, 0, NULL}
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const char *mg_get_builtin_mime_type(const char *path)
 | 
	
	
		
			
				|  | @@ -3514,7 +3547,7 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog)
 | 
	
		
			
				|  |  |      char *buf;
 | 
	
		
			
				|  |  |      size_t buflen;
 | 
	
		
			
				|  |  |      int headers_len, data_len, i, fdin[2] = { 0, 0 }, fdout[2] = { 0, 0 };
 | 
	
		
			
				|  |  | -    const char *status, *status_text;
 | 
	
		
			
				|  |  | +    const char *status, *status_text, *connection_state;
 | 
	
		
			
				|  |  |      char *pbuf, dir[PATH_MAX], *p;
 | 
	
		
			
				|  |  |      struct mg_request_info ri;
 | 
	
		
			
				|  |  |      struct cgi_env_block blk;
 | 
	
	
		
			
				|  | @@ -3624,8 +3657,9 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog)
 | 
	
		
			
				|  |  |      } else {
 | 
	
		
			
				|  |  |          conn->status_code = 200;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    if (get_header(&ri, "Connection") != NULL &&
 | 
	
		
			
				|  |  | -        !mg_strcasecmp(get_header(&ri, "Connection"), "keep-alive")) {
 | 
	
		
			
				|  |  | +    connection_state = get_header(&ri, "Connection");
 | 
	
		
			
				|  |  | +    if (connection_state == NULL ||
 | 
	
		
			
				|  |  | +        mg_strcasecmp(connection_state, "keep-alive")) {
 | 
	
		
			
				|  |  |          conn->must_close = 1;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      (void) mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code,
 | 
	
	
		
			
				|  | @@ -5729,12 +5763,17 @@ static void master_thread_run(void *thread_func_param)
 | 
	
		
			
				|  |  |      // Increase priority of the master thread
 | 
	
		
			
				|  |  |  #if defined(_WIN32)
 | 
	
		
			
				|  |  |      SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -#if defined(ISSUE_317)
 | 
	
		
			
				|  |  | -    struct sched_param sched_param;
 | 
	
		
			
				|  |  | -    sched_param.sched_priority = sched_get_priority_max(SCHED_RR);
 | 
	
		
			
				|  |  | -    pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param);
 | 
	
		
			
				|  |  | +#elif defined(USE_MASTER_THREAD_PRIORITY)
 | 
	
		
			
				|  |  | +    int min_prio = sched_get_priority_min(SCHED_RR);
 | 
	
		
			
				|  |  | +    int max_prio = sched_get_priority_max(SCHED_RR);
 | 
	
		
			
				|  |  | +    if ((min_prio >=0) && (max_prio >= 0) &&
 | 
	
		
			
				|  |  | +        ((USE_MASTER_THREAD_PRIORITY) <= max_prio) &&
 | 
	
		
			
				|  |  | +        ((USE_MASTER_THREAD_PRIORITY) >= min_prio)
 | 
	
		
			
				|  |  | +        ) {
 | 
	
		
			
				|  |  | +            struct sched_param sched_param = {0};
 | 
	
		
			
				|  |  | +            sched_param.sched_priority = (USE_MASTER_THREAD_PRIORITY);
 | 
	
		
			
				|  |  | +            pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      pfd = (struct pollfd *) calloc(ctx->num_listening_sockets, sizeof(pfd[0]));
 |