-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.yaws?file=%2Fsession1.yaws
64 lines (53 loc) · 1.84 KB
/
code.yaws?file=%2Fsession1.yaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<div>
<h2>/session1.yaws</h2>
<div>
<pre><erl>
-record(myopaque, {udata,
times = 0,
foobar}).
out(A) ->
H = A#arg.headers,
C = H#headers.cookie,
case yaws_api:find_cookie_val("baz", C) of
[] ->
M = #myopaque{},
Cookie = yaws_api:new_cookie_session(M),
Data = {ehtml,
{html,[],
["I just set your cookie to ", Cookie, "Click ",
{a, [{href,"session1.yaws"}], " here "},
"to revisit"]}},
CO = yaws_api:set_cookie("baz",Cookie,[{path,"/"}]),
[Data, CO];
Cookie ->
case yaws_api:cookieval_to_opaque(Cookie) of
{ok, OP} ->
OP2 = OP#myopaque{times = OP#myopaque.times + 1},
yaws_api:replace_cookie_session(Cookie, OP2),
Data = {ehtml,
{html,[],
[
"Click ",
{a, [{href,"session1.yaws"}], " here "},
"to revisit",
{p, [], f("You have been here ~p times",
[OP2#myopaque.times])},
{p, [], f("Your cookie is ~s", [Cookie])}]}},
Data;
{error, no_session} ->
new_session()
end
end.
new_session() ->
M = #myopaque{},
Cookie = yaws_api:new_cookie_session(M),
Data = {ehtml,
{html,[],
["I just set your cookie to ", Cookie, "Click ",
{a, [{href,"session1.yaws"}], " here "},
"to revisit"]}},
CO = yaws_api:set_cookie("baz",Cookie,[{path,"/"}]),
[Data, CO].
</erl>
</pre></div></div></html>