aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Chlipala <adam@chlipala.net>2018-10-19 15:55:17 -0400
committerAdam Chlipala <adam@chlipala.net>2018-10-19 15:55:17 -0400
commitd800556bd50ecb78c21343a288f9475b8b870162 (patch)
treed031992d3d4d6809969b712ba44ace1eaea667e3
parente798117b42c5df30d1b3778d6414467e8e7b1e04 (diff)
Just return None rather than crashing, when trying to read cookies within tasks (closes #143)
-rw-r--r--src/c/urweb.c5
-rw-r--r--tests/task_cookie.ur9
2 files changed, 13 insertions, 1 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index e7efae38..2e3e18bc 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -737,7 +737,10 @@ void uw_close(uw_context ctx) {
}
uw_Basis_string uw_Basis_requestHeader(uw_context ctx, uw_Basis_string h) {
- return ctx->get_header(ctx->get_header_data, h);
+ if (ctx->get_header)
+ return ctx->get_header(ctx->get_header_data, h);
+ else
+ return NULL;
}
void uw_set_headers(uw_context ctx, char *(*get_header)(void *, const char *), void *get_header_data) {
diff --git a/tests/task_cookie.ur b/tests/task_cookie.ur
new file mode 100644
index 00000000..39f49b0a
--- /dev/null
+++ b/tests/task_cookie.ur
@@ -0,0 +1,9 @@
+cookie myCookie: {Value: string}
+
+fun main (): transaction page = return <xml></xml>
+
+task initialize = fn () =>
+ c <- getCookie myCookie;
+ case c of
+ None => debug "No cookie"
+ | Some {Value = v} => debug ("Cookie value: " ^ v)