Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 62 lines (46 sloc) 1.51 kb
d69e4d8 @klacke ""
authored
1
961926f @klacke ""
authored
2
f448988 @klacke ""
authored
3 <erl>
4
5 session(A, Visits) ->
6 receive
0be3c7e @klacke untabified all of yaws
authored
7 {From, tick} ->
8 N = calendar:local_time(),
9 From ! {self(), [N|Visits]},
10 session(A, [N|Visits])
d69e4d8 @klacke ""
authored
11 after 60000 -> %% keep state for 60 secs only
0be3c7e @klacke untabified all of yaws
authored
12 exit(normal)
f448988 @klacke ""
authored
13 end.
14
d69e4d8 @klacke ""
authored
15
3b9e4a1 @klacke new ret vals from out/1
authored
16 out(A) ->
d69e4d8 @klacke ""
authored
17 H = A#arg.headers,
18 C = H#headers.cookie,
961926f @klacke ""
authored
19 case yaws_api:find_cookie_val("foobar", C) of
0be3c7e @klacke untabified all of yaws
authored
20 [] ->
3b9e4a1 @klacke new ret vals from out/1
authored
21 Now = calendar:local_time(),
0be3c7e @klacke untabified all of yaws
authored
22 P = spawn(fun() -> session(A, [Now]) end),
7811247 @vinoski whitespace cleanup
vinoski authored
23 yaws_api:setcookie("foobar",
0be3c7e @klacke untabified all of yaws
authored
24 pid_to_list(P), "/");
25 PidStr ->
26 Pid = list_to_pid(PidStr),
27 case process_info(Pid, messages) of
28 undefined ->
29 Now = calendar:local_time(),
7811247 @vinoski whitespace cleanup
vinoski authored
30 P = spawn(fun() ->
31 session(A, [Now])
0be3c7e @klacke untabified all of yaws
authored
32 end),
7811247 @vinoski whitespace cleanup
vinoski authored
33 yaws_api:setcookie("foobar",
0be3c7e @klacke untabified all of yaws
authored
34 pid_to_list(P), "/");
35 _ ->
36 ok
37 end
d69e4d8 @klacke ""
authored
38 end.
39
40 </erl>
41
42 <html>
43
44
45 <h2> set cookie </h2>
46
47 <p>This is the page that set the cookie in the browser.
7811247 @vinoski whitespace cleanup
vinoski authored
48 <a href="readcookie.yaws">readcookie.yaws</a> will
49 read the cookie and report persistent information as
a5e3fa4 @klacke ""
authored
50 long as the browser session exists.
51
7811247 @vinoski whitespace cleanup
vinoski authored
52 <p> it will set the cookie
a5e3fa4 @klacke ""
authored
53 <tt>foobar = &lt;x,y,z&gt;; </tt> where the
7811247 @vinoski whitespace cleanup
vinoski authored
54 x,y,z string is the textual representation of an
55 actual erlang pid which will be responsible for
a5e3fa4 @klacke ""
authored
56 this session.
d69e4d8 @klacke ""
authored
57
58 </html>
59
60
7811247 @vinoski whitespace cleanup
vinoski authored
61
Something went wrong with that request. Please try again.