diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index b38a8669..02c344ef 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit b38a866916d166fba8a33275b9375f185fcf3671 +Subproject commit 02c344efb0eba8bd4f1eec8fb5dce3db5bda284a diff --git a/src/Common/config.cpp b/src/Common/config.cpp index a35df89e..b9e00b02 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -93,6 +93,10 @@ const char kKeepAliveSecond[] = HTTP_FIELD"keepAliveSecond"; #define HTTP_MAX_REQ_CNT 100 const char kMaxReqCount[] = HTTP_FIELD"maxReqCount"; +//文件服务器是否启动虚拟主机 +const char kEnableVhost[] = HTTP_FIELD"enableVhost"; + + //http 字符编码 #if defined(_WIN32) #define HTTP_CHAR_SET "gb2312" @@ -126,6 +130,7 @@ onceToken token([](){ mINI::Instance()[kCharSet] = HTTP_CHAR_SET; mINI::Instance()[kRootPath] = HTTP_ROOT_PATH; mINI::Instance()[kNotFound] = HTTP_NOT_FOUND; + mINI::Instance()[kEnableVhost] = 1; },nullptr); }//namespace Http diff --git a/src/Common/config.h b/src/Common/config.h index 3ba7a819..7f49715c 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -165,6 +165,8 @@ extern const char kCharSet[]; extern const char kRootPath[]; //http 404错误提示内容 extern const char kNotFound[]; +//文件服务器是否启动虚拟主机 +extern const char kEnableVhost[]; }//namespace Http diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 02fe0cce..94b1ae99 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -105,9 +105,6 @@ HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) { pSock->setSendTimeOutSecond(15); //起始接收buffer缓存设置为4K,节省内存 pSock->setReadBuffer(std::make_shared(4 * 1024)); - - GET_CONFIG_AND_REGISTER(string,rootPath,Http::kRootPath); - _strPath = rootPath; } HttpSession::~HttpSession() { @@ -266,6 +263,9 @@ inline bool HttpSession::checkLiveFlvStream(){ } return true; } + +inline bool makeMeun(const string &httpPath,const string &strFullPath,const string &vhost, string &strRet) ; + inline bool HttpSession::Handle_Req_GET(int64_t &content_len) { //先看看是否为WebSocket请求 if(checkWebSocket()){ @@ -293,16 +293,19 @@ inline bool HttpSession::Handle_Req_GET(int64_t &content_len) { auto fullUrl = string(HTTP_SCHEMA) + "://" + _parser["Host"] + _parser.FullUrl(); _mediaInfo.parse(fullUrl); - string strFile = _strPath + "/" + _mediaInfo._vhost + _parser.Url(); /////////////HTTP连接是否需要被关闭//////////////// GET_CONFIG_AND_REGISTER(uint32_t,reqCnt,Http::kMaxReqCount); + GET_CONFIG_AND_REGISTER(bool,enableVhost,Http::kEnableVhost); + GET_CONFIG_AND_REGISTER(string,rootPath,Http::kRootPath); + string strFile = enableVhost ? rootPath + "/" + _mediaInfo._vhost + _parser.Url() :rootPath + _parser.Url(); + replace(strFile,"//","/"); bool bClose = (strcasecmp(_parser["Connection"].data(),"close") == 0) || ( ++_iReqCnt > reqCnt); //访问的是文件夹 if (strFile.back() == '/' || File::is_dir(strFile.data())) { //生成文件夹菜单索引 string strMeun; - if (!makeMeun(strFile,_mediaInfo._vhost, strMeun)) { + if (!makeMeun(_parser.Url(),strFile,_mediaInfo._vhost, strMeun)) { //文件夹不存在 sendNotFound(bClose); return !bClose; @@ -432,7 +435,7 @@ inline bool HttpSession::Handle_Req_GET(int64_t &content_len) { return true; } -inline bool HttpSession::makeMeun(const string &strFullPath,const string &vhost, string &strRet) { +inline bool makeMeun(const string &httpPath,const string &strFullPath,const string &vhost, string &strRet) { string strPathPrefix(strFullPath); string last_dir_name; if(strPathPrefix.back() == '/'){ @@ -452,11 +455,9 @@ inline bool HttpSession::makeMeun(const string &strFullPath,const string &vhost, "\r\n" "

文件索引:"; - string strPath = strFullPath; - strPath = strPath.substr(_strPath.length() + vhost.length() + 1); - ss << strPath; + ss << httpPath; ss << "

\r\n"; - if (strPath != "/") { + if (httpPath != "/") { ss << "
  • "; diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 1e96be35..94cb345c 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -97,7 +97,6 @@ protected: } private: Parser _parser; - string _strPath; Ticker _ticker; uint32_t _iReqCnt = 0; //消耗的总流量 @@ -113,7 +112,6 @@ private: inline bool checkWebSocket(); inline bool emitHttpEvent(bool doInvoke); inline void urlDecode(Parser &parser); - inline bool makeMeun(const string &strFullPath,const string &vhost, string &strRet); inline void sendNotFound(bool bClose); inline void sendResponse(const char *pcStatus,const KeyValue &header,const string &strContent); inline static KeyValue makeHttpHeader(bool bClose=false,int64_t iContentSize=-1,const char *pcContentType="text/html");