# HG changeset patch # User Adam Chlipala # Date 1259331166 18000 # Node ID 7e3226c97678ca04e034f6409c3af48a619a2331 # Parent 731e6aa6655ae993acee74192b7ca61cf4f90f80 Fix handling of clearCookie/getCookie in same page gen diff -r 731e6aa6655a -r 7e3226c97678 src/c/urweb.c --- 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; } diff -r 731e6aa6655a -r 7e3226c97678 tests/vlad3.ur --- /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 + Welcome {[u.EMail]}. Logout + + +and logout () = + clearCookie user; + main () + +and login () = return +
E-mail: +
+ +and signin r = + setCookie user {Value = {EMail = r.EMail}, + Expires = None, (* Some (readError "2012-11-6 +00:00:00"), *) + Secure = False + }; + main () diff -r 731e6aa6655a -r 7e3226c97678 tests/vlad3.urp --- /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 diff -r 731e6aa6655a -r 7e3226c97678 tests/vlad3.urs --- /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