diff --git a/lib/src/HttpControllersRouter.cc b/lib/src/HttpControllersRouter.cc index 09f98e5e..2e9b5037 100644 --- a/lib/src/HttpControllersRouter.cc +++ b/lib/src/HttpControllersRouter.cc @@ -25,8 +25,8 @@ void HttpControllersRouter::init() for (auto &router : _ctrlVector) { std::regex reg("\\(\\[\\^/\\]\\*\\)"); - std::string tmp = std::regex_replace(router.pathParameterPattern, reg, "[^/]*"); - router._regex = std::regex(router.pathParameterPattern, std::regex_constants::icase); + std::string tmp = std::regex_replace(router._pathParameterPattern, reg, "[^/]*"); + router._regex = std::regex(router._pathParameterPattern, std::regex_constants::icase); regString.append("(").append(tmp).append(")|"); } if (regString.length() > 0) @@ -90,15 +90,15 @@ void HttpControllersRouter::addHttpPath(const std::string &path, } auto pathParameterPattern = std::regex_replace(originPath, regex, "([^/]*)"); auto binderInfo = CtrlBinderPtr(new CtrlBinder); - binderInfo->filtersName = filters; - binderInfo->binderPtr = binder; - binderInfo->parameterPlaces = std::move(places); - binderInfo->queryParametersPlaces = std::move(parametersPlaces); + binderInfo->_filtersName = filters; + binderInfo->_binderPtr = binder; + binderInfo->_parameterPlaces = std::move(places); + binderInfo->_queryParametersPlaces = std::move(parametersPlaces); { std::lock_guard guard(_ctrlMutex); for (auto &router : _ctrlVector) { - if (router.pathParameterPattern == pathParameterPattern) + if (router._pathParameterPattern == pathParameterPattern) { if (validMethods.size() > 0) { @@ -117,7 +117,7 @@ void HttpControllersRouter::addHttpPath(const std::string &path, } } struct HttpControllerRouterItem router; - router.pathParameterPattern = pathParameterPattern; + router._pathParameterPattern = pathParameterPattern; if (validMethods.size() > 0) { for (auto const &method : validMethods) @@ -156,7 +156,7 @@ void HttpControllersRouter::route(const HttpRequestImplPtr &req, { size_t ctlIndex = i - 1; auto &routerItem = _ctrlVector[ctlIndex]; - //LOG_TRACE << "got http access,regex=" << binder.pathParameterPattern; + //LOG_TRACE << "got http access,regex=" << binder._pathParameterPattern; assert(Invalid > req->method()); auto &binder = routerItem._binders[req->method()]; if (!binder) @@ -167,12 +167,12 @@ void HttpControllersRouter::route(const HttpRequestImplPtr &req, callback(res); return; } - auto &filters = binder->filtersName; + auto &filters = binder->_filtersName; if (!filters.empty()) { auto sessionIdPtr = std::make_shared(std::move(sessionId)); auto callbackPtr = std::make_shared>(std::move(callback)); - _appImpl.doFilters(filters, req, callbackPtr, needSetJsessionid, sessionIdPtr, [=]() { + _appImpl.doFilters(filters, req, callbackPtr, needSetJsessionid, sessionIdPtr, [=, &binder, &routerItem]() { doControllerHandler(binder, routerItem, req, std::move(*callbackPtr), needSetJsessionid, std::move(*sessionIdPtr)); }); } @@ -211,8 +211,8 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP { HttpResponsePtr responsePtr; { - std::lock_guard guard(*(ctrlBinderPtr->binderMtx)); - responsePtr = ctrlBinderPtr->responsePtr; + std::lock_guard guard(ctrlBinderPtr->_binderMtx); + responsePtr = ctrlBinderPtr->_responsePtr; } if (responsePtr && (responsePtr->expiredTime() == 0 || (trantor::Date::now() < responsePtr->createDate().after(responsePtr->expiredTime())))) @@ -232,28 +232,28 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP } return; } - std::vector params(ctrlBinderPtr->parameterPlaces.size()); + std::vector params(ctrlBinderPtr->_parameterPlaces.size()); std::smatch r; if (std::regex_match(req->path(), r, routerItem._regex)) { for (size_t j = 1; j < r.size(); j++) { - size_t place = ctrlBinderPtr->parameterPlaces[j - 1]; + size_t place = ctrlBinderPtr->_parameterPlaces[j - 1]; if (place > params.size()) params.resize(place); params[place - 1] = r[j].str(); LOG_TRACE << "place=" << place << " para:" << params[place - 1]; } } - if (ctrlBinderPtr->queryParametersPlaces.size() > 0) + if (ctrlBinderPtr->_queryParametersPlaces.size() > 0) { auto qureyPara = req->getParameters(); for (auto const ¶meter : qureyPara) { - if (ctrlBinderPtr->queryParametersPlaces.find(parameter.first) != - ctrlBinderPtr->queryParametersPlaces.end()) + if (ctrlBinderPtr->_queryParametersPlaces.find(parameter.first) != + ctrlBinderPtr->_queryParametersPlaces.end()) { - auto place = ctrlBinderPtr->queryParametersPlaces.find(parameter.first)->second; + auto place = ctrlBinderPtr->_queryParametersPlaces.find(parameter.first)->second; if (place > params.size()) params.resize(place); params[place - 1] = parameter.second; @@ -261,12 +261,12 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP } } std::list paraList; - for (auto &p : params)///Use reference + for (auto &p : params) ///Use reference { LOG_TRACE << p; paraList.push_back(std::move(p)); } - ctrlBinderPtr->binderPtr->handleHttpRequest(paraList, req, [=, callback = std::move(callback), sessionId = std::move(sessionId)](const HttpResponsePtr &resp) { + ctrlBinderPtr->_binderPtr->handleHttpRequest(paraList, req, [=, callback = std::move(callback), sessionId = std::move(sessionId)](const HttpResponsePtr &resp) { LOG_TRACE << "http resp:needSetJsessionid=" << needSetJsessionid << ";JSESSIONID=" << sessionId; auto newResp = resp; if (resp->expiredTime() >= 0) @@ -274,8 +274,8 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP //cache the response; std::dynamic_pointer_cast(resp)->makeHeaderString(); { - std::lock_guard guard(*(ctrlBinderPtr->binderMtx)); - ctrlBinderPtr->responsePtr = resp; + std::lock_guard guard(ctrlBinderPtr->_binderMtx); + ctrlBinderPtr->_responsePtr = resp; } } if (needSetJsessionid) diff --git a/lib/src/HttpControllersRouter.h b/lib/src/HttpControllersRouter.h index 2eff81f5..9cb85528 100644 --- a/lib/src/HttpControllersRouter.h +++ b/lib/src/HttpControllersRouter.h @@ -43,17 +43,17 @@ class HttpControllersRouter : public trantor::NonCopyable private: struct CtrlBinder { - internal::HttpBinderBasePtr binderPtr; - std::vector filtersName; - std::vector parameterPlaces; - std::map queryParametersPlaces; - std::unique_ptr binderMtx = std::unique_ptr(new std::mutex); - std::shared_ptr responsePtr; + internal::HttpBinderBasePtr _binderPtr; + std::vector _filtersName; + std::vector _parameterPlaces; + std::map _queryParametersPlaces; + std::mutex _binderMtx; + std::shared_ptr _responsePtr; }; typedef std::shared_ptr CtrlBinderPtr; struct HttpControllerRouterItem { - std::string pathParameterPattern; + std::string _pathParameterPattern; std::regex _regex; CtrlBinderPtr _binders[Invalid]; //The enum value Invalid is the http methods number }; diff --git a/lib/src/HttpSimpleControllersRouter.cc b/lib/src/HttpSimpleControllersRouter.cc index c318531b..2203b731 100644 --- a/lib/src/HttpSimpleControllersRouter.cc +++ b/lib/src/HttpSimpleControllersRouter.cc @@ -51,8 +51,8 @@ void HttpSimpleControllersRouter::registerHttpSimpleController(const std::string } } auto &item = _simpCtrlMap[path]; - item.controllerName = ctrlName; - item.filtersName = filters; + item._controllerName = ctrlName; + item._filtersName = filters; item._validMethodsFlags.clear(); //There may be old data, first clear if (validMethods.size() > 0) { @@ -62,12 +62,12 @@ void HttpSimpleControllersRouter::registerHttpSimpleController(const std::string item._validMethodsFlags[method] = 1; } } - auto controller = item.controller; + auto controller = item._controller; if (!controller) { auto _object = std::shared_ptr(DrClassMap::newObject(ctrlName)); controller = std::dynamic_pointer_cast(_object); - item.controller = controller; + item._controller = controller; } } @@ -94,7 +94,7 @@ void HttpSimpleControllersRouter::route(const HttpRequestImplPtr &req, return; } } - auto &filters = ctrlInfo.filtersName; + auto &filters = ctrlInfo._filtersName; if (!filters.empty()) { auto sessionIdPtr = std::make_shared(std::move(sessionId)); @@ -118,15 +118,15 @@ void HttpSimpleControllersRouter::doControllerHandler(SimpleControllerRouterItem bool needSetJsessionid, std::string &&sessionId) { - const std::string &ctrlName = item.controllerName; - auto &controller = item.controller; + const std::string &ctrlName = item._controllerName; + auto &controller = item._controller; if (controller) { HttpResponsePtr responsePtr; { //maybe update controller,so we use lock_guard to protect; std::lock_guard guard(item._mutex); - responsePtr = item.responsePtr; + responsePtr = item._responsePtr; } if (responsePtr && (responsePtr->expiredTime() == 0 || (trantor::Date::now() < responsePtr->createDate().after(responsePtr->expiredTime())))) { @@ -154,7 +154,7 @@ void HttpSimpleControllersRouter::doControllerHandler(SimpleControllerRouterItem std::dynamic_pointer_cast(resp)->makeHeaderString(); { std::lock_guard guard(item._mutex); - item.responsePtr = resp; + item._responsePtr = resp; } } if (needSetJsessionid) diff --git a/lib/src/HttpSimpleControllersRouter.h b/lib/src/HttpSimpleControllersRouter.h index a9df2365..dc41fb66 100644 --- a/lib/src/HttpSimpleControllersRouter.h +++ b/lib/src/HttpSimpleControllersRouter.h @@ -47,11 +47,11 @@ class HttpSimpleControllersRouter : public trantor::NonCopyable HttpControllersRouter &_httpCtrlsRouter; struct SimpleControllerRouterItem { - std::string controllerName; - std::vector filtersName; + std::string _controllerName; + std::vector _filtersName; std::vector _validMethodsFlags; - std::shared_ptr controller; - std::shared_ptr responsePtr; + std::shared_ptr _controller; + std::shared_ptr _responsePtr; std::mutex _mutex; }; std::unordered_map _simpCtrlMap;