winlin

for #293, refine the mime of content type.

@@ -341,26 +341,46 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* @@ -341,26 +341,46 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
341 341
342 w->header()->set_content_length(length); 342 w->header()->set_content_length(length);
343 343
344 - if (srs_string_ends_with(fullpath, ".ts")) {  
345 - w->header()->set_content_type("video/MP2T");  
346 - } else if (srs_string_ends_with(fullpath, ".m3u8")) {  
347 - w->header()->set_content_type("application/x-mpegURL;charset=utf-8");  
348 - } else if (srs_string_ends_with(fullpath, ".flv")) {  
349 - w->header()->set_content_type("video/x-flv");  
350 - } else if (srs_string_ends_with(fullpath, ".xml")) {  
351 - w->header()->set_content_type("text/xml;charset=utf-8");  
352 - } else if (srs_string_ends_with(fullpath, ".js")) {  
353 - w->header()->set_content_type("text/javascript");  
354 - } else if (srs_string_ends_with(fullpath, ".json")) {  
355 - w->header()->set_content_type("application/json;charset=utf-8");  
356 - } else if (srs_string_ends_with(fullpath, ".swf")) {  
357 - w->header()->set_content_type("application/x-shockwave-flash");  
358 - } else if (srs_string_ends_with(fullpath, ".css")) {  
359 - w->header()->set_content_type("text/css;charset=utf-8");  
360 - } else if (srs_string_ends_with(fullpath, ".ico")) {  
361 - w->header()->set_content_type("image/x-icon");  
362 - } else {  
363 - w->header()->set_content_type("text/html;charset=utf-8"); 344 + static std::map<std::string, std::string> _mime;
  345 + if (_mime.empty()) {
  346 + _mime[".ts"] = "video/MP2T";
  347 + _mime[".flv"] = "video/x-flv";
  348 + _mime[".m4v"] = "video/x-m4v";
  349 + _mime[".3gpp"] = "video/3gpp";
  350 + _mime[".3gp"] = "video/3gpp";
  351 + _mime[".mp4"] = "video/mp4";
  352 + _mime[".mp3"] = "audio/mpeg";
  353 + _mime[".m4a"] = "audio/x-m4a";
  354 + _mime[".ogg"] = "audio/ogg";
  355 + _mime[".m3u8"] = "application/x-mpegURL;charset=utf-8";
  356 + _mime[".rss"] = "application/rss+xml";
  357 + _mime[".json"] = "application/json;charset=utf-8";
  358 + _mime[".swf"] = "application/x-shockwave-flash";
  359 + _mime[".doc"] = "application/msword";
  360 + _mime[".zip"] = "application/zip";
  361 + _mime[".rar"] = "application/x-rar-compressed";
  362 + _mime[".xml"] = "text/xml;charset=utf-8";
  363 + _mime[".js"] = "text/javascript";
  364 + _mime[".css"] = "text/css;charset=utf-8";
  365 + _mime[".ico"] = "image/x-icon";
  366 + _mime[".png"] = "image/png";
  367 + _mime[".jpeg"] = "image/jpeg";
  368 + _mime[".jpg"] = "image/jpeg";
  369 + _mime[".gif"] = "image/gif";
  370 + }
  371 +
  372 + if (true) {
  373 + ssize_t pos;
  374 + std::string ext = fullpath;
  375 + if ((pos = ext.rfind(".")) != string::npos) {
  376 + ext = ext.substr(pos);
  377 + }
  378 +
  379 + if (_mime.find(ext) == _mime.end()) {
  380 + w->header()->set_content_type("text/html;charset=utf-8");
  381 + } else {
  382 + w->header()->set_content_type(_mime[ext]);
  383 + }
364 } 384 }
365 385
366 // write body. 386 // write body.