changeset 1052:7e3226c97678

Fix handling of clearCookie/getCookie in same page gen
author Adam Chlipala <adamc@hcoop.net>
date Fri, 27 Nov 2009 09:12:46 -0500
parents 731e6aa6655a
children 118a5a08a881
files src/c/urweb.c tests/vlad3.ur tests/vlad3.urp tests/vlad3.urs
diffstat 4 files changed, 41 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Nov 26 14:58:03 2009 -0500
+++ b/src/c/urweb.c	Fri Nov 27 09:12:46 2009 -0500
@@ -2645,6 +2645,8 @@
   return b;
 }
 
+#define THE_PAST "expires=Mon, 01-01-1970 00:00:00 GMT"
+
 uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
   int len = strlen(c);
   char *p = ctx->outHeaders.start;
@@ -2658,10 +2660,14 @@
       size_t sz = strcspn(p2+1, ";\r\n");
 
       if (!strncasecmp(p, c, p2 - p)) {
-        char *ret = uw_malloc(ctx, sz + 1);
-        memcpy(ret, p2+1, sz);
-        ret[sz] = 0;
-        return ret;
+        if (sz == 0 && strstr(p2+2, THE_PAST))
+          return NULL;
+        else {
+          char *ret = uw_malloc(ctx, sz + 1);
+          memcpy(ret, p2+1, sz);
+          ret[sz] = 0;
+          return ret;
+        }
       }
     }
   }
@@ -2719,7 +2725,7 @@
   uw_write_header(ctx, c);
   uw_write_header(ctx, "=; path=");
   uw_write_header(ctx, prefix);
-  uw_write_header(ctx, "; expires=Mon, 01-01-1970 00:00:00 GMT\r\n");
+  uw_write_header(ctx, "; " THE_PAST "\r\n");
 
   return uw_unit_v;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vlad3.ur	Fri Nov 27 09:12:46 2009 -0500
@@ -0,0 +1,27 @@
+cookie user : {EMail : string}
+
+fun main () =
+    ro <- getCookie user;
+    case ro of
+        Some u => welcome u
+      | _ => login ()
+
+and welcome u = return <xml><body>
+  Welcome {[u.EMail]}. <a link={logout ()}>Logout</a>
+</body></xml>
+
+and logout () =
+    clearCookie user;
+    main ()
+
+and login () = return <xml><body>
+  <form>E-mail:<textbox{#EMail}/><submit action={signin}/></form>
+</body></xml>
+   
+and signin r =
+    setCookie user {Value = {EMail = r.EMail},
+                    Expires = None, (* Some (readError "2012-11-6
+00:00:00"), *)
+                    Secure = False
+                   };
+    main ()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vlad3.urp	Fri Nov 27 09:12:46 2009 -0500
@@ -0,0 +1,2 @@
+
+vlad3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vlad3.urs	Fri Nov 27 09:12:46 2009 -0500
@@ -0,0 +1,1 @@
+val main : unit -> transaction page