# HG changeset patch # User Adam Chlipala # Date 1225998230 18000 # Node ID 1626dcba13ee27b5ba74094ee4e9753f33553886 # Parent ddd363e856ff5741c14b87aaf8aa2d8b8019eec1 Cookies work across pages diff -r ddd363e856ff -r 1626dcba13ee include/urweb.h --- a/include/urweb.h Thu Nov 06 12:46:45 2008 -0500 +++ b/include/urweb.h Thu Nov 06 14:03:50 2008 -0500 @@ -6,7 +6,7 @@ extern uw_unit uw_unit_v; -uw_context uw_init(size_t page_len, size_t heap_len); +uw_context uw_init(size_t outHeaders_len, size_t page_len, size_t heap_len); void uw_set_db(uw_context, void*); void *uw_get_db(uw_context); void uw_free(uw_context); @@ -101,5 +101,5 @@ void uw_write_header(uw_context, uw_Basis_string); -uw_Basis_string uw_Basis_get_cookie(uw_context, uw_Basis_string); -uw_unit uw_Basis_set_cookie(uw_context, uw_Basis_string, uw_Basis_string); +uw_Basis_string uw_Basis_get_cookie(uw_context, uw_Basis_string c); +uw_unit uw_Basis_set_cookie(uw_context, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v); diff -r ddd363e856ff -r 1626dcba13ee src/c/driver.c --- a/src/c/driver.c Thu Nov 06 12:46:45 2008 -0500 +++ b/src/c/driver.c Thu Nov 06 14:03:50 2008 -0500 @@ -71,7 +71,7 @@ static void *worker(void *data) { int me = *(int *)data, retries_left = MAX_RETRIES; - uw_context ctx = uw_init(1024, 0); + uw_context ctx = uw_init(0, 1024, 0); while (1) { failure_kind fk = uw_begin_init(ctx); diff -r ddd363e856ff -r 1626dcba13ee src/c/urweb.c --- a/src/c/urweb.c Thu Nov 06 12:46:45 2008 -0500 +++ b/src/c/urweb.c Thu Nov 06 14:03:50 2008 -0500 @@ -1152,11 +1152,13 @@ } } -uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string c, uw_Basis_string v) { +uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v) { uw_write_header(ctx, "Set-Cookie: "); uw_write_header(ctx, c); uw_write_header(ctx, "="); uw_write_header(ctx, v); + uw_write_header(ctx, "; path="); + uw_write_header(ctx, prefix); uw_write_header(ctx, "\r\n"); return uw_unit_v; diff -r ddd363e856ff -r 1626dcba13ee src/monoize.sml --- a/src/monoize.sml Thu Nov 06 12:46:45 2008 -0500 +++ b/src/monoize.sml Thu Nov 06 14:03:50 2008 -0500 @@ -971,7 +971,10 @@ ((L'.EAbs ("c", s, (L'.TFun (t, (L'.TFun (un, un), loc)), loc), (L'.EAbs ("v", t, (L'.TFun (un, un), loc), (L'.EAbs ("_", un, un, - (L'.EFfiApp ("Basis", "set_cookie", [(L'.ERel 2, loc), e]), loc)), + (L'.EFfiApp ("Basis", "set_cookie", [(L'.EPrim (Prim.String (!urlPrefix)), + loc), + (L'.ERel 2, loc), + e]), loc)), loc)), loc)), loc), fm) end diff -r ddd363e856ff -r 1626dcba13ee tests/cookie.ur --- a/tests/cookie.ur Thu Nov 06 12:46:45 2008 -0500 +++ b/tests/cookie.ur Thu Nov 06 14:03:50 2008 -0500 @@ -1,8 +1,22 @@ cookie c : string -fun main () : transaction page = - setCookie c "Hi"; +fun other () = so <- getCookie c; case so of None => return No cookie | Some s => return Cookie: {[s]} + +structure M = struct + fun aux () = + setCookie c "Hi"; + so <- getCookie c; + case so of + None => return No cookie + | Some s => return Cookie: {[s]}
+ Other
+end + +fun main () : transaction page = return + Other
+ Aux
+