Skip to content
Newer
Older
100644 61 lines (39 sloc) 1.56 KB
f448988 @klacke ""
authored Feb 20, 2002
1 <erl>
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored Nov 19, 2004
2 out(A) ->
20ece13 @klacke more css hackery
authored Dec 2, 2004
3 {ssi, "TAB.inc", "%%",[{"cookies", "choosen"}]}.
f448988 @klacke ""
authored Feb 20, 2002
4 </erl>
5
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored Nov 19, 2004
6 <div id="entry">
7
f448988 @klacke ""
authored Feb 20, 2002
8
9
10 <h1>Yaws and Cookies</h1>
11 <p>
12 Cookies are the means in HTTP to assign data to a session. A HTTP session
13 typically consists of many (and sometimes concurrent) TCP connections from the
14 client to the web server. The first time a client arrives to our webserver, we
d69e4d8 @klacke ""
authored Feb 25, 2002
15 issue the HTTP header <tt>Set-Cookie: var=someval</tt>. The browser will then in
16 subsequent connections to the same server pass this cookie "var=someval" in its
17 client side <tt>Cookie: var=someval</tt> header. We can thereby assign state to a
f448988 @klacke ""
authored Feb 20, 2002
18 session, either through data actualy encoded into the cookie value itself, or by
19 associating server side session data to the cookie.
20 <p>
d69e4d8 @klacke ""
authored Feb 25, 2002
21
f448988 @klacke ""
authored Feb 20, 2002
22 Let's do an example where we set a simple cookie, and create a specific erlang process
d69e4d8 @klacke ""
authored Feb 25, 2002
23 which is then responsible for that session.
24 The cookie value will be a string encoding of the pid handling the session.
f448988 @klacke ""
authored Feb 20, 2002
25
26 <p>
d69e4d8 @klacke ""
authored Feb 25, 2002
27 The yaws code in
28 <a href="setcookie.yaws">setcookie.yaws</a> sets the cookie in the browser.
f448988 @klacke ""
authored Feb 20, 2002
29
d69e4d8 @klacke ""
authored Feb 25, 2002
30 <p>And the yaws code in <a href="readcookie.yaws">readcookie.yaws</a>
31 will read the cookie
f448988 @klacke ""
authored Feb 20, 2002
32 and report some uninteresting session data.
33
34
35
36 A correct definition of cookies can be found at Netscapes
37 <a href="http://www.netscape.com/newsref/std/cookie_spec.html">cookie spec</a>
d69e4d8 @klacke ""
authored Feb 25, 2002
38
39
40 <p>The code to set the cookie looks like:
41
42 <erl>
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored Nov 19, 2004
43 out(A) ->
44 {ok, B} = file:read_file(A#arg.docroot ++ "/setcookie.yaws"),
45 {ehtml,
46 {'div', [{class, "box"}],
47 {pre,[], B}}}.
48
d69e4d8 @klacke ""
authored Feb 25, 2002
49 </erl>
50
51
52
53
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored Nov 19, 2004
54 </div>
55
56
57 <erl>
58 out(A) -> {ssi, "END2",[],[]}.
59 </erl>
d69e4d8 @klacke ""
authored Feb 25, 2002
60
Something went wrong with that request. Please try again.