for #293, refine the mime of content type.

pull/133/head
winlin 10 years ago
parent 3b853a6dbd
commit d546827b1c

@ -341,26 +341,46 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
w->header()->set_content_length(length); w->header()->set_content_length(length);
if (srs_string_ends_with(fullpath, ".ts")) { static std::map<std::string, std::string> _mime;
w->header()->set_content_type("video/MP2T"); if (_mime.empty()) {
} else if (srs_string_ends_with(fullpath, ".m3u8")) { _mime[".ts"] = "video/MP2T";
w->header()->set_content_type("application/x-mpegURL;charset=utf-8"); _mime[".flv"] = "video/x-flv";
} else if (srs_string_ends_with(fullpath, ".flv")) { _mime[".m4v"] = "video/x-m4v";
w->header()->set_content_type("video/x-flv"); _mime[".3gpp"] = "video/3gpp";
} else if (srs_string_ends_with(fullpath, ".xml")) { _mime[".3gp"] = "video/3gpp";
w->header()->set_content_type("text/xml;charset=utf-8"); _mime[".mp4"] = "video/mp4";
} else if (srs_string_ends_with(fullpath, ".js")) { _mime[".mp3"] = "audio/mpeg";
w->header()->set_content_type("text/javascript"); _mime[".m4a"] = "audio/x-m4a";
} else if (srs_string_ends_with(fullpath, ".json")) { _mime[".ogg"] = "audio/ogg";
w->header()->set_content_type("application/json;charset=utf-8"); _mime[".m3u8"] = "application/x-mpegURL;charset=utf-8";
} else if (srs_string_ends_with(fullpath, ".swf")) { _mime[".rss"] = "application/rss+xml";
w->header()->set_content_type("application/x-shockwave-flash"); _mime[".json"] = "application/json;charset=utf-8";
} else if (srs_string_ends_with(fullpath, ".css")) { _mime[".swf"] = "application/x-shockwave-flash";
w->header()->set_content_type("text/css;charset=utf-8"); _mime[".doc"] = "application/msword";
} else if (srs_string_ends_with(fullpath, ".ico")) { _mime[".zip"] = "application/zip";
w->header()->set_content_type("image/x-icon"); _mime[".rar"] = "application/x-rar-compressed";
} else { _mime[".xml"] = "text/xml;charset=utf-8";
_mime[".js"] = "text/javascript";
_mime[".css"] = "text/css;charset=utf-8";
_mime[".ico"] = "image/x-icon";
_mime[".png"] = "image/png";
_mime[".jpeg"] = "image/jpeg";
_mime[".jpg"] = "image/jpeg";
_mime[".gif"] = "image/gif";
}
if (true) {
ssize_t pos;
std::string ext = fullpath;
if ((pos = ext.rfind(".")) != string::npos) {
ext = ext.substr(pos);
}
if (_mime.find(ext) == _mime.end()) {
w->header()->set_content_type("text/html;charset=utf-8"); w->header()->set_content_type("text/html;charset=utf-8");
} else {
w->header()->set_content_type(_mime[ext]);
}
} }
// write body. // write body.

Loading…
Cancel
Save