Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 59 lines (48 sloc) 1.786 kb
0d158e5 @klacke ""
authored
1 <erl>
2
3 -record(myopaque, {udata,
0be3c7e @klacke untabified all of yaws
authored
4 times = 0,
5 foobar}).
0d158e5 @klacke ""
authored
6
7 out(A) ->
8 H = A#arg.headers,
9 C = H#headers.cookie,
10 case yaws_api:find_cookie_val("baz", C) of
0be3c7e @klacke untabified all of yaws
authored
11 [] ->
12 M = #myopaque{},
13 Cookie = yaws_api:new_cookie_session(M),
14 Data = {ehtml,
15 {html,[],
16 ["I just set your cookie to ", Cookie, "Click ",
17 {a, [{href,"session1.yaws"}], " here "},
18 "to revisit"]}},
19 CO = yaws_api:setcookie("baz",Cookie,"/"),
20 [Data, CO];
21 Cookie ->
2470367 @klacke handle expired cookie sessions in the example
authored
22 case yaws_api:cookieval_to_opaque(Cookie) of
23 {ok, OP} ->
24 OP2 = OP#myopaque{times = OP#myopaque.times + 1},
25 yaws_api:replace_cookie_session(Cookie, OP2),
26 Data = {ehtml,
27 {html,[],
28 [
29 "Click ",
30 {a, [{href,"session1.yaws"}], " here "},
31 "to revisit",
7811247 @vinoski whitespace cleanup
vinoski authored
32 {p, [], f("You have been here ~p times",
2470367 @klacke handle expired cookie sessions in the example
authored
33 [OP2#myopaque.times])},
34 {p, [], f("Your cookie is ~s", [Cookie])}]}},
35 Data;
36 {error, no_session} ->
37 new_session()
38 end
0d158e5 @klacke ""
authored
39 end.
40
2470367 @klacke handle expired cookie sessions in the example
authored
41
42 new_session() ->
43 M = #myopaque{},
44 Cookie = yaws_api:new_cookie_session(M),
7811247 @vinoski whitespace cleanup
vinoski authored
45
2470367 @klacke handle expired cookie sessions in the example
authored
46 Data = {ehtml,
47 {html,[],
48 ["I just set your cookie to ", Cookie, "Click ",
49 {a, [{href,"session1.yaws"}], " here "},
7811247 @vinoski whitespace cleanup
vinoski authored
50
2470367 @klacke handle expired cookie sessions in the example
authored
51 "to revisit"]}},
52 CO = yaws_api:setcookie("baz",Cookie,"/"),
53 [Data, CO].
54
55
56
0d158e5 @klacke ""
authored
57 </erl>
58
Something went wrong with that request. Please try again.