V8CGI Session API


Yesterday we started to do some tests on the server side APIs we will need.
The Session api described here http://code.google.com/p/v8cgi/wiki/API_Session looks like is not up to date.
In every file, if you want to use the session, you must add this on the top and recall the session variable this way:

var session = new (require('session').Session)(request, response);

In the session is possible to save values, objects made with functions and JSON objects without any problem.
In the end of every script the session is saved automatically.
The attach files are a little example with the session usage of the 3 types:
sessput.sjs puts variables in the session, sessread.sjs reads and write it on the browser

file attachments


leooo wrote May 26, 2011 at 4:01 PM

I tried to build a little Dom and save it in the session; just few elements copied from the DOM API made by this little XML :
<root><node1 /><node2 a='b'>xxx</node2></root>

First we tried to save the Dom tree, and we got a null value in the session.
I called the save() method explicitly and noticed that i got this answer ...

"TypeError: Converting circular structure to JSON (/opt/v8cgi/lib/session.js:58) TypeError: Converting circular structure to JSON at Object.stringify (native) at [object Object].save (/opt/v8cgi/lib/session.js:58:17) at Object. (/var/www/v8/sessionwrite.sjs:36:9)"

so we can't save the entire tree by simply adding the domroot in the session, but we have to serialize and deserialize it every time at starting of every serverpage.

leooo wrote May 26, 2011 at 4:21 PM

I added 2 file in the SVN with the serialization working :)

DOMsessionread and DOMsessionwrite :)

leooo wrote May 26, 2011 at 4:22 PM

I added 2 easy examples with the serialization of the dom and retrieving from the session in the other page.

DOMsessionwrite and DOMsessionread :)

wrote Jan 24, 2013 at 6:17 PM