#define DROGON_TEST_MAIN #include #include #include #include #include using namespace drogon; using namespace trantor; class CookieSameSiteController : public drogon::HttpController { public: static const char *SESSION_SAME_SITE; METHOD_LIST_BEGIN METHOD_ADD(CookieSameSiteController::set, "/set/{newSameSite}", Get); METHOD_LIST_END void set(const HttpRequestPtr &req, std::function &&callback, std::string &&newSameSite) { LOG_TRACE << "new sameSite == " << newSameSite; std::string old_session_same_site = "Null"; if (req->session()->find(SESSION_SAME_SITE)) { old_session_same_site = req->session()->get(SESSION_SAME_SITE); LOG_TRACE << "old value: " << old_session_same_site; } drogon::HttpAppFramework::instance().enableSession( 0, Cookie::convertString2SameSite(newSameSite)); req->session()->modify( SESSION_SAME_SITE, [newSameSite](std::string &sameSite) { sameSite = newSameSite; }); Json::Value json; json["result"] = "ok"; json["old value"] = old_session_same_site; json["new value"] = newSameSite; auto resp = HttpResponse::newHttpJsonResponse(std::move(json)); callback(resp); } }; const char *CookieSameSiteController::SESSION_SAME_SITE{"session_same_site"}; // -- main int main(int argc, char **argv) { trantor::Logger::setLogLevel(trantor::Logger::kTrace); std::promise p1; std::future f1 = p1.get_future(); std::thread thr([&]() { app() .setSSLFiles("server.pem", "server.pem") .addListener("0.0.0.0", 8849, true) .enableSession(); app().getLoop()->queueInLoop([&p1]() { p1.set_value(); }); app().run(); }); f1.get(); int testStatus = test::run(argc, argv); app().getLoop()->queueInLoop([]() { app().quit(); }); thr.join(); return testStatus; }