Set session to requests for websockets (#521)
This commit is contained in:
parent
5e35055379
commit
820715cd62
|
@ -514,7 +514,6 @@ void HttpAppFrameworkImpl::run()
|
|||
// TODO: new plugin
|
||||
});
|
||||
}
|
||||
|
||||
getLoop()->queueInLoop([this]() {
|
||||
// Let listener event loops run when everything is ready.
|
||||
listenerManagerPtr_->startListening();
|
||||
|
@ -614,11 +613,27 @@ HttpAppFramework &HttpAppFrameworkImpl::setUploadPath(
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
void HttpAppFrameworkImpl::findSessionForRequest(const HttpRequestImplPtr &req)
|
||||
{
|
||||
if (useSession_)
|
||||
{
|
||||
std::string sessionId = req->getCookie("JSESSIONID");
|
||||
bool needSetJsessionid = false;
|
||||
if (sessionId.empty())
|
||||
{
|
||||
sessionId = utils::getUuid();
|
||||
needSetJsessionid = true;
|
||||
}
|
||||
req->setSession(
|
||||
sessionManagerPtr_->getSession(sessionId, needSetJsessionid));
|
||||
}
|
||||
}
|
||||
void HttpAppFrameworkImpl::onNewWebsockRequest(
|
||||
const HttpRequestImplPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback,
|
||||
const WebSocketConnectionImplPtr &wsConnPtr)
|
||||
{
|
||||
findSessionForRequest(req);
|
||||
// Route to controller
|
||||
if (!preRoutingObservers_.empty())
|
||||
{
|
||||
|
@ -744,18 +759,7 @@ void HttpAppFrameworkImpl::onAsyncRequest(
|
|||
callback(resp);
|
||||
return;
|
||||
}
|
||||
if (useSession_)
|
||||
{
|
||||
std::string sessionId = req->getCookie("JSESSIONID");
|
||||
bool needSetJsessionid = false;
|
||||
if (sessionId.empty())
|
||||
{
|
||||
sessionId = utils::getUuid();
|
||||
needSetJsessionid = true;
|
||||
}
|
||||
req->setSession(
|
||||
sessionManagerPtr_->getSession(sessionId, needSetJsessionid));
|
||||
}
|
||||
findSessionForRequest(req);
|
||||
// Route to controller
|
||||
if (!preRoutingObservers_.empty())
|
||||
{
|
||||
|
|
|
@ -512,6 +512,8 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
|||
const std::vector<HttpMethod> &validMethods,
|
||||
const std::vector<std::string> &filters);
|
||||
|
||||
void findSessionForRequest(const HttpRequestImplPtr &req);
|
||||
|
||||
// We use a uuid string as session id;
|
||||
// set sessionTimeout_=0 to make location session valid forever based on
|
||||
// cookies;
|
||||
|
|
Loading…
Reference in New Issue