mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-03 20:27:49 +08:00
Merge pull request #148 from an-tao/cookies_bug_fix
Disable cookies on 404 pages
This commit is contained in:
commit
52bc179b51
@ -36,7 +36,7 @@ static void doFilterChains(const std::vector<std::shared_ptr<HttpFilterBase>> &f
|
||||
auto &filter = filters[index];
|
||||
filter->doFilter(req,
|
||||
[needSetJsessionid, callbackPtr, sessionIdPtr](const HttpResponsePtr &res) {
|
||||
if (needSetJsessionid)
|
||||
if (needSetJsessionid && res->statusCode() != k404NotFound)
|
||||
res->addCookie("JSESSIONID", *sessionIdPtr);
|
||||
(*callbackPtr)(res);
|
||||
},
|
||||
|
@ -817,7 +817,7 @@ void HttpAppFrameworkImpl::onAsyncRequest(const HttpRequestImplPtr &req, std::fu
|
||||
0,
|
||||
req,
|
||||
std::make_shared<std::function<void(const HttpResponsePtr &)>>([callbackPtr, needSetJsessionid, sessionIdPtr](const HttpResponsePtr &resp) {
|
||||
if (!needSetJsessionid)
|
||||
if (!needSetJsessionid || resp->statusCode() == k404NotFound)
|
||||
(*callbackPtr)(resp);
|
||||
else
|
||||
{
|
||||
|
@ -266,8 +266,6 @@ void HttpControllersRouter::route(const HttpRequestImplPtr &req,
|
||||
{
|
||||
//No controller found
|
||||
auto res = drogon::HttpResponse::newNotFoundResponse();
|
||||
if (needSetJsessionid)
|
||||
res->addCookie("JSESSIONID", sessionId);
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
@ -275,8 +273,6 @@ void HttpControllersRouter::route(const HttpRequestImplPtr &req,
|
||||
{
|
||||
//No controller found
|
||||
auto res = drogon::HttpResponse::newNotFoundResponse();
|
||||
if (needSetJsessionid)
|
||||
res->addCookie("JSESSIONID", sessionId);
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
@ -294,7 +290,7 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP
|
||||
//use cached response!
|
||||
LOG_TRACE << "Use cached response";
|
||||
|
||||
if (!needSetJsessionid)
|
||||
if (!needSetJsessionid || responsePtr->statusCode() == k404NotFound)
|
||||
invokeCallback(callback, req, responsePtr);
|
||||
else
|
||||
{
|
||||
@ -360,7 +356,7 @@ void HttpControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlBinderP
|
||||
});
|
||||
}
|
||||
}
|
||||
if (needSetJsessionid)
|
||||
if (needSetJsessionid && resp->statusCode() != k404NotFound)
|
||||
{
|
||||
if (resp->expiredTime() >= 0)
|
||||
{
|
||||
@ -427,7 +423,7 @@ void HttpControllersRouter::doPreHandlingAdvices(const CtrlBinderPtr &ctrlBinder
|
||||
0,
|
||||
req,
|
||||
std::make_shared<std::function<void(const HttpResponsePtr &)>>([callbackPtr, needSetJsessionid, sessionIdPtr](const HttpResponsePtr &resp) {
|
||||
if (!needSetJsessionid)
|
||||
if (!needSetJsessionid || resp->statusCode() == k404NotFound)
|
||||
(*callbackPtr)(resp);
|
||||
else
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ class HttpResponseImpl : public HttpResponse
|
||||
{
|
||||
friend class HttpResponseParser;
|
||||
|
||||
public:
|
||||
public:
|
||||
HttpResponseImpl()
|
||||
: _statusCode(kUnknown),
|
||||
_creationDate(trantor::Date::now()),
|
||||
@ -240,12 +240,12 @@ class HttpResponseImpl : public HttpResponse
|
||||
|
||||
virtual void addCookie(const std::string &key, const std::string &value) override
|
||||
{
|
||||
_cookies.insert(std::make_pair(key, Cookie(key, value)));
|
||||
_cookies[key] = Cookie(key, value);
|
||||
}
|
||||
|
||||
virtual void addCookie(const Cookie &cookie) override
|
||||
{
|
||||
_cookies.insert(std::make_pair(cookie.key(), cookie));
|
||||
_cookies[cookie.key()] = cookie;
|
||||
}
|
||||
|
||||
virtual const Cookie &getCookie(const std::string &key, const Cookie &defaultCookie = Cookie()) const override
|
||||
@ -378,10 +378,10 @@ class HttpResponseImpl : public HttpResponse
|
||||
_bodyPtr = gunzipBody;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void makeHeaderString(const std::shared_ptr<std::string> &headerStringPtr) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> _headers;
|
||||
std::unordered_map<std::string, Cookie> _cookies;
|
||||
|
||||
|
@ -176,7 +176,7 @@ void HttpSimpleControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlB
|
||||
{
|
||||
//use cached response!
|
||||
LOG_TRACE << "Use cached response";
|
||||
if (!needSetJsessionid)
|
||||
if (!needSetJsessionid || responsePtr->statusCode() == k404NotFound)
|
||||
invokeCallback(callback, req, responsePtr);
|
||||
else
|
||||
{
|
||||
@ -208,7 +208,7 @@ void HttpSimpleControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlB
|
||||
});
|
||||
}
|
||||
}
|
||||
if (needSetJsessionid)
|
||||
if (needSetJsessionid && resp->statusCode() != k404NotFound)
|
||||
{
|
||||
if (resp->expiredTime() >= 0)
|
||||
{
|
||||
@ -229,8 +229,6 @@ void HttpSimpleControllersRouter::doControllerHandler(const CtrlBinderPtr &ctrlB
|
||||
const std::string &ctrlName = ctrlBinderPtr->_controllerName;
|
||||
LOG_ERROR << "can't find controller " << ctrlName;
|
||||
auto res = drogon::HttpResponse::newNotFoundResponse();
|
||||
if (needSetJsessionid)
|
||||
res->addCookie("JSESSIONID", sessionId);
|
||||
invokeCallback(callback, req, res);
|
||||
}
|
||||
}
|
||||
@ -326,7 +324,7 @@ void HttpSimpleControllersRouter::doPreHandlingAdvices(const CtrlBinderPtr &ctrl
|
||||
0,
|
||||
req,
|
||||
std::make_shared<std::function<void(const HttpResponsePtr &)>>([callbackPtr, needSetJsessionid, sessionIdPtr](const HttpResponsePtr &resp) {
|
||||
if (!needSetJsessionid)
|
||||
if (!needSetJsessionid || resp->statusCode() == k404NotFound)
|
||||
(*callbackPtr)(resp);
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user