The above methods are all called through the HttpAppFramework
singleton. The timeout parameter represents the time when the session is invalid. The unit is second. The default value is 1200. That is, if the user does not access the web application for more than 20 minutes, the corresponding session will be invalid. Setting timeout to 0 means that drogon will retain the user’s session for the entire lifetime;
The sameSite parameter changes the SameSite attribute of the Set-Cookie HTTP response header.
Make sure your client supports cookies before opening the session feature. Otherwise, drogon will create a new session for each request without cookie, which will waste memory and computing resources.
The drogon framework will pass the session object to the object and pass it to the user. The user can get the Session object through the following interface of the HttpRequest
class.
The interface returns a smart pointer of the Session
object, through which various objects can be accessed;
Examples of sessions
We create a Filter to implement this function, assuming the class name is TimeFilter, the implementation is as follows:
We then register a lambda expression to the path and attach the TimeFilter with the following code:
Recompile the entire project with CMake, run the target program webapp, and you can see the effect through the browser.