Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

62 lines (43 sloc) 1.738 kb
<html>
<h2> Read cookie </h2>
<erl>
out(A) ->
H=A#arg.headers,
C = H#headers.cookie,
L=case yaws_api:find_cookie_val("foobar", C) of
[] ->
f("<p> No cookie set from the browser, need to "
"visit <a href=\"setcookie.yaws\">setcookie.yaws</a> "
"to set the cookie first ~n", []);
PidStr ->
Pid = list_to_pid(PidStr),
Pid ! {self(), tick},
receive
{Pid, VisitList} ->
f("<p> Yes, I read your cookie "
"You have vistited this page ~w times "
"they were ~n<ol> ~n~s </ol>~n "
"Reloading this page will show the session state ",
[length(VisitList),
lists:map(fun(D) ->
f("<li> ~p~n", [D]) end,
VisitList)
])
after 500 ->
f("<p> You had a cookie, but the pid handling your sess "
"timedout ...",[])
end
end,
{html, L}.
</erl>
<p>
The code to read the cookie, is simple, we get the cookie passed to the yaws
code in the #arg structure which is the argument supplied to the out/1 function.
<p>We use the <tt>yaws_api:find_cookie_val/2</tt> function to parse
the raw cookie string passed to us from the browser.
The code is:
<erl>
out(A) ->
yaws_api:pre_ssi_files(A#arg.docroot, ["readcookie.yaws"]).
</erl>
</html>
Jump to Line
Something went wrong with that request. Please try again.