add some method in HttpAppFramework
This commit is contained in:
parent
6c7512bdf4
commit
4a8cb46f43
|
@ -111,7 +111,8 @@ int main()
|
|||
func=std::bind(&A::handle,&tmp,_1,_2,_3,_4,_5,_6);
|
||||
//api example for std::function
|
||||
drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle4/{4}/{3}/{1}",func);
|
||||
LOG_DEBUG<<drogon::DrObjectBase::demangle(typeid(func).name());
|
||||
|
||||
//start app framework
|
||||
drogon::HttpAppFramework::instance().run();
|
||||
|
||||
}
|
||||
|
|
|
@ -76,5 +76,8 @@ namespace drogon
|
|||
}
|
||||
virtual void enableSession(const size_t timeout=0)=0;
|
||||
virtual void disableSession()=0;
|
||||
virtual const std::string & getDocumentRoot() const =0;
|
||||
virtual void setDocumentRoot(const std::string &rootPath)=0;
|
||||
virtual void setFileTypes(const std::vector<std::string> &types)=0;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -48,6 +48,9 @@ namespace drogon
|
|||
const std::vector<std::string> &filters=std::vector<std::string>()) override ;
|
||||
virtual void enableSession(const size_t timeout) override { _useSession=true;_sessionTimeout=timeout;}
|
||||
virtual void disableSession() override { _useSession=false;}
|
||||
virtual const std::string & getDocumentRoot() const override {return _rootPath;}
|
||||
virtual void setDocumentRoot(const std::string &rootPath) override {_rootPath=rootPath;}
|
||||
virtual void setFileTypes(const std::vector<std::string> &types) override;
|
||||
~HttpAppFrameworkImpl(){}
|
||||
private:
|
||||
std::vector<std::pair<std::string,uint16_t>> _listeners;
|
||||
|
@ -95,7 +98,7 @@ namespace drogon
|
|||
std::regex _apiRegex;
|
||||
bool _enableLastModify=true;
|
||||
std::set<std::string> _fileTypeSet={"html","jpg"};
|
||||
std::string _rootPath;
|
||||
std::string _rootPath=".";
|
||||
|
||||
|
||||
|
||||
|
@ -111,6 +114,13 @@ namespace drogon
|
|||
|
||||
using namespace drogon;
|
||||
using namespace std::placeholders;
|
||||
void HttpAppFrameworkImpl::setFileTypes(const std::vector<std::string> &types)
|
||||
{
|
||||
for(auto type : types)
|
||||
{
|
||||
_fileTypeSet.insert(type);
|
||||
}
|
||||
}
|
||||
void HttpAppFrameworkImpl::initRegex() {
|
||||
std::string regString;
|
||||
for(auto binder:_apiCtrlVector)
|
||||
|
@ -334,7 +344,7 @@ void HttpAppFrameworkImpl::onAsyncRequest(const HttpRequest& req,const std::func
|
|||
std::string path = req.path();
|
||||
auto pos = path.rfind(".");
|
||||
if(pos != std::string::npos) {
|
||||
std::string filetype = path.substr(pos + 1, path.length());
|
||||
std::string filetype = path.substr(pos + 1);
|
||||
transform(filetype.begin(), filetype.end(), filetype.begin(), tolower);
|
||||
if(_fileTypeSet.find(filetype) != _fileTypeSet.end()) {
|
||||
LOG_INFO << "file query!";
|
||||
|
|
Loading…
Reference in New Issue