Closed behindmagic9 closed 1 year ago
Drogon uses cookie based session. This is a widely used technology, you could google it out easily.
do drogon automatically handles the sessionId or we do have to provide one
If you set enable_session: true
if config, drogon will automatically search for JSESSIONID
cookie in resquest header, and add set-cookie header in responses. For every JSESSIONID, there is a session allocated in memory. Custom data should be stored in session.
If client send requests with correct JSESSIONID cookie, drogon will find the corresponding session. Use HttpRequest::getSession()
to get it, and use it like a map to store your custom data.
if any client does not let support cookies then how it handles that
To make session work, client side must handle cookie correctly. Normal web browsers will handle cookie automatically.
HTTP is a stateless protocol. If client side does not send back cookie(for example, using incognito mode in chrome), you could NEVER make use of cookie-based session. In this case, every request send by client will be treated as from a new sender and a new session will be allocated for it. This would be a waste of memory.
Nothing special to explain here, just regular cookie. Both HttpRequest
and HttpResponse
have getCookie()
and addCookie()
apis.
ohkayy , can you please correct my code above that be very helpful in clear understanding of this ?? !!
@hwc0919 just to clarify. You said:
Drogon allocates
Session
in memory.
Isn’t this a bit prodigal? Are there any other options for Session
storage?
i don't find this in the documentation of the drogon , do drogon automatically handles the sessionId or we do have to provide one ?? whats the cookie and sessionId mechanism in drogon ??if any client does not let support cookies then how it handles that , by url ?? or nay other alternate method ?how ??? what header top include while setting/adding up the cookie especially in Json format , like storing session id as well as user information?? And ... can anybody please tell me whats wrong in these handler? its showing parse error in storeJsonInCookie handler and not retrieving any from the retrieving handler !!