out(A) -> {ssi, "TAB.inc", "%%",[{"cookies", "choosen"}]}.

Yaws and Cookies

Cookies are the means in HTTP to assign data to a session. A HTTP session typically consists of many (and sometimes concurrent) TCP connections from the client to the web server. The first time a client arrives to our webserver, we issue the HTTP header Set-Cookie: var=someval. The browser will then in subsequent connections to the same server pass this cookie "var=someval" in its client side Cookie: var=someval header. We can thereby assign state to a session, either through data actualy encoded into the cookie value itself, or by associating server side session data to the cookie.

Let's do an example where we set a simple cookie, and create a specific erlang process which is then responsible for that session. The cookie value will be a string encoding of the pid handling the session.

The yaws code in setcookie.yaws sets the cookie in the browser.

And the yaws code in readcookie.yaws will read the cookie and report some uninteresting session data.

A correct definition of cookies can be found at Netscapes cookie spec

The code to set the cookie looks like:

out(A) -> {ok, B} = file:read_file(A#arg.docroot ++ "/setcookie.yaws"), {ehtml, {'div', [{class, "box"}], {pre,[], B}}}.
out(A) -> {ssi, "END2",[],[]}.