Re: [Cppcms-users] SSE keep-alive
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2013-04-03 06:48:05
|
----- Original Message -----
> 2013/4/2 Artyom Beilis <art...@ya...>:
>> Small notes:
>>
>> 1. Session is saved when the output stream is accessed first time, as you
>> need to provide set session cookies.
>>
>> Remember the session data may be stored entirely on the client
>> side in signed cookies.
>>
>
> "session" : {
> "expire" : "renew",
> "timeout" : 15,
> "location" : "server",
> "gc" : 10,
> "server": {
> "storage":"memory"
> }
> },
>
> The session data itself is store on the server side - or?
>
>> Saving session after output was provided is similar to an attempt
>> to set a cookie **after** HTTP headers were sent.
>>
>
> Okay
>
>> 2. Calling changing session values and calling save after the output
>> was generated has undefined behavior.
>>
>
> I am not changing any value stored in the session. I only want to renew
> the session. For me it is a problem when the cppcms session gets deleted
> if a script runs e.g. 15 minutes. On the client side there is only one open
> SSE stream.
Why wouldn't you increase the timeout on session such that it would not expire so quickly?
In general session is something long running - months, days, sometime hours for more sensitive
applications and tens of minutes for very sensitive applications like banking web sites.
The primary role of session is to carry user identification and other various user
specific properties.
>
>> So your code is incorrect.
>>
>> I think you mix up two different things: HTTP Stream session - the
>> state where the connection is open and you push the data to the stream
>> (it is represented by cppcms::http::context and actual open TCP/IP socket)
>> and the CppCMS/Web session the information shared **accorss** different
>> connections - that is based cookies - the state for stateless HTTP.
>>
>
> As far as I can tell from studying the source code a cppcms::http::context gets
> created if the client does a get/post.
> This context has access to the request(), the response() and the assigned cppcms
> session().
>
> In my case the life-time strategy is set to "renew". This means the
> client needs to
> do a get/post to create a cppcms::http::context as this action will
> trigger the "renew"
> logic - or?
>
> Is there a way to do the "renew" of the cppcms::session from the
> server side?
> Again from reading the code the cppcms::sessions::session_storage class
> provides methods to load and save session data. The garbage logic is inside
> such a inherited class.
No, if there is no request the session would get expired, regardless garbage
collection.
GC is needed to collect expired sessions but the session expiration does not
depend on GC, it is session specific property.
>
> If the session data is stored on the server side and the cookie in the
> browser only stores
> the session key it should be possible to renew a cppcms::session.
> And this is what I doing in this code snippet.
>
> void session_interface::renew_session()
> {
> loaded_ = 0;
> saved_ = 0;
>
> load();
> save();
> }
>
> If there is no way to "renew" the cppcms::session on the server side,
> I need to
> add some js code to the client side doing silly gets to trigger the
> "renew" of
> the cppcms::session.
>
I understand what you say but this is not something that is supported.
You may open a feature request to provide an access to server side
session storage from an API that is not connected to a specific
cppcms::http::context and renew session.
What you can actually do is to implement an alternative server side storage:
http://cppcms.com/cppcms_ref/1.0.2/classcppcms_1_1sessions_1_1session__storage.html
That would allow you to handle the timeout in different way and probably update
the session from your application directly.
But this is a hack.
> thanks
> --
> Christian Gmeiner, MSc
>
Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.com/
CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
|