Commit 9c45fca7 by xiongguangjie Committed by GitHub

根据配置禁用mmap缓存 (#1429)

parent af08b58d
...@@ -193,6 +193,10 @@ dirMenu=1 ...@@ -193,6 +193,10 @@ dirMenu=1
#访问 http://127.0.0.1/app_b/file_b 对应的文件路径为 /path/to/b/file_b #访问 http://127.0.0.1/app_b/file_b 对应的文件路径为 /path/to/b/file_b
#访问其他http路径,对应的文件路径还是在rootPath内 #访问其他http路径,对应的文件路径还是在rootPath内
virtualPath= virtualPath=
#禁止后缀的文件缓存,使用“,”隔开
#例如赋值为 .mp4,.flv
#那么访问后缀为.mp4与.flv 的文件不缓存
forbidCacheSuffix=
[multicast] [multicast]
#rtp组播截止组播ip地址 #rtp组播截止组播ip地址
......
...@@ -127,6 +127,8 @@ const string kNotFound = HTTP_FIELD"notFound"; ...@@ -127,6 +127,8 @@ const string kNotFound = HTTP_FIELD"notFound";
//是否显示文件夹菜单 //是否显示文件夹菜单
const string kDirMenu = HTTP_FIELD"dirMenu"; const string kDirMenu = HTTP_FIELD"dirMenu";
const string kForbidCacheSuffix = HTTP_FIELD"forbidCacheSuffix";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kSendBufSize] = 64 * 1024; mINI::Instance()[kSendBufSize] = 64 * 1024;
mINI::Instance()[kMaxReqSize] = 4 * 10240; mINI::Instance()[kMaxReqSize] = 4 * 10240;
...@@ -151,6 +153,7 @@ onceToken token([](){ ...@@ -151,6 +153,7 @@ onceToken token([](){
"</body>" "</body>"
"</html>" "</html>"
<< endl; << endl;
mINI::Instance()[kForbidCacheSuffix] = "";
},nullptr); },nullptr);
}//namespace Http }//namespace Http
......
...@@ -214,6 +214,8 @@ extern const std::string kVirtualPath; ...@@ -214,6 +214,8 @@ extern const std::string kVirtualPath;
extern const std::string kNotFound; extern const std::string kNotFound;
//是否显示文件夹菜单 //是否显示文件夹菜单
extern const std::string kDirMenu; extern const std::string kDirMenu;
//禁止缓存文件的后缀
extern const std::string kForbidCacheSuffix;
}//namespace Http }//namespace Http
////////////SHELL配置/////////// ////////////SHELL配置///////////
......
...@@ -357,6 +357,7 @@ static string pathCat(const string &a, const string &b){ ...@@ -357,6 +357,7 @@ static string pathCat(const string &a, const string &b){
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) { static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
bool is_hls = end_with(file_path, kHlsSuffix); bool is_hls = end_with(file_path, kHlsSuffix);
bool file_exist = File::is_file(file_path.data()); bool file_exist = File::is_file(file_path.data());
bool is_forbid_cache = false;
if (!is_hls && !file_exist) { if (!is_hls && !file_exist) {
//文件不存在且不是hls,那么直接返回404 //文件不存在且不是hls,那么直接返回404
sendNotFound(cb); sendNotFound(cb);
...@@ -369,9 +370,18 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo ...@@ -369,9 +370,18 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
replace(const_cast<string &>(media_info._streamid), kHlsSuffix, ""); replace(const_cast<string &>(media_info._streamid), kHlsSuffix, "");
} }
GET_CONFIG_FUNC(vector<string>, forbidCacheSuffix, Http::kForbidCacheSuffix, [](const string &str) {
return split(str,",");
});
for (auto &suffix : forbidCacheSuffix) {
if(suffix != "" && end_with(file_path, suffix)){
is_forbid_cache = true;
break;
}
}
weak_ptr<TcpSession> weakSession = sender.shared_from_this(); weak_ptr<TcpSession> weakSession = sender.shared_from_this();
//判断是否有权限访问该文件 //判断是否有权限访问该文件
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession , file_exist](const string &err_msg, const HttpServerCookie::Ptr &cookie) { canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls,is_forbid_cache, media_info, weakSession , file_exist](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
auto strongSession = weakSession.lock(); auto strongSession = weakSession.lock();
if (!strongSession) { if (!strongSession) {
//http客户端已经断开,不需要回复 //http客户端已经断开,不需要回复
...@@ -387,7 +397,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo ...@@ -387,7 +397,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
return; return;
} }
auto response_file = [file_exist, is_hls](const HttpServerCookie::Ptr &cookie, const HttpFileManager::invoker &cb, auto response_file = [file_exist, is_hls, is_forbid_cache](const HttpServerCookie::Ptr &cookie, const HttpFileManager::invoker &cb,
const string &file_path, const Parser &parser, const string &file_content = "") { const string &file_path, const Parser &parser, const string &file_content = "") {
StrCaseMap httpHeader; StrCaseMap httpHeader;
if (cookie) { if (cookie) {
...@@ -402,7 +412,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo ...@@ -402,7 +412,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
} }
cb(code, HttpFileManager::getContentType(file_path.data()), headerOut, body); cb(code, HttpFileManager::getContentType(file_path.data()), headerOut, body);
}; };
invoker.responseFile(parser.getHeader(), httpHeader, file_content.empty() ? file_path : file_content, !is_hls, file_content.empty()); invoker.responseFile(parser.getHeader(), httpHeader, file_content.empty() ? file_path : file_content, !is_hls && !is_forbid_cache, file_content.empty());
}; };
if (!is_hls || !cookie) { if (!is_hls || !cookie) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论