添加kBroadcastHttpBeforeAccess事件,拦截http文件下载事件

This commit is contained in:
xiongziliang
2019-12-23 12:47:04 +08:00
parent 0b8c4e75e1
commit 2da0c884a1
4 changed files with 17 additions and 7 deletions

View File

@@ -375,6 +375,14 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
});
}
static string getFilePath(const Parser &parser,const MediaInfo &mediaInfo, TcpSession &sender){
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
GET_CONFIG(string, rootPath, Http::kRootPath);
auto ret = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, mediaInfo, ret, sender);
return std::move(ret);
}
/**
* 访问文件或文件夹
* @param sender 事件触发者
@@ -384,11 +392,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const HttpFileManager::invoker &cb) {
auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl();
MediaInfo mediaInfo(fullUrl);
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
GET_CONFIG(string, rootPath, Http::kRootPath);
auto strFile = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
auto strFile = getFilePath(parser, mediaInfo, sender);
//访问的是文件夹
if (File::is_dir(strFile.data())) {
auto indexFile = searchIndexFile(strFile);