summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-11-27 09:12:46 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-11-27 09:12:46 -0500
commit6fe3b9b161042130f6df278defee7dfd8ae6850d (patch)
tree15b6d42341953d7bdb5b73f29445391070b5b57d
parentb9982e3f5bb8c01d2b2b787b39d3a0b6796d0e8d (diff)
Fix handling of clearCookie/getCookie in same page gen
-rw-r--r--src/c/urweb.c16
-rw-r--r--tests/vlad3.ur27
-rw-r--r--tests/vlad3.urp2
-rw-r--r--tests/vlad3.urs1
4 files changed, 41 insertions, 5 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index aaa1278f..d1a5d320 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -2645,6 +2645,8 @@ uw_Basis_blob uw_Basis_stringToBlob_error(uw_context ctx, uw_Basis_string s, siz
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 @@ uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) {
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_unit uw_Basis_clear_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_s
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 --git a/tests/vlad3.ur b/tests/vlad3.ur
new file mode 100644
index 00000000..3d1e812b
--- /dev/null
+++ b/tests/vlad3.ur
@@ -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 ()
diff --git a/tests/vlad3.urp b/tests/vlad3.urp
new file mode 100644
index 00000000..3a0fa1f3
--- /dev/null
+++ b/tests/vlad3.urp
@@ -0,0 +1,2 @@
+
+vlad3
diff --git a/tests/vlad3.urs b/tests/vlad3.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/tests/vlad3.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page