summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demo/cookie.ur26
-rw-r--r--demo/cookie.urp2
-rw-r--r--demo/cookie.urs1
-rw-r--r--src/c/driver.c23
-rw-r--r--src/c/urweb.c12
5 files changed, 43 insertions, 21 deletions
diff --git a/demo/cookie.ur b/demo/cookie.ur
new file mode 100644
index 00000000..02f4cab5
--- /dev/null
+++ b/demo/cookie.ur
@@ -0,0 +1,26 @@
+cookie c : {A : string, B : float, C : int}
+
+fun set r =
+ setCookie c {A = r.A, B = readError r.B, C = readError r.C};
+ return <xml>Cookie set.</xml>
+
+fun main () =
+ ro <- getCookie c;
+ let
+ val xml = case ro of
+ None => <xml>No cookie set.</xml>
+ | Some v => <xml>Cookie: A = {[v.A]}, B = {[v.B]}, C = {[v.C]}</xml>
+ in
+ return <xml><body>
+ {xml}<br/><br/>
+
+ <form>
+ A: <textbox{#A}/><br/>
+ B: <textbox{#B}/><br/>
+ C: <textbox{#C}/><br/>
+ <submit action={set}/>
+ </form>
+ </body></xml>
+ end
+
+
diff --git a/demo/cookie.urp b/demo/cookie.urp
new file mode 100644
index 00000000..9e283d4b
--- /dev/null
+++ b/demo/cookie.urp
@@ -0,0 +1,2 @@
+
+cookie
diff --git a/demo/cookie.urs b/demo/cookie.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/demo/cookie.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page
diff --git a/src/c/driver.c b/src/c/driver.c
index 438adb8d..d884c025 100644
--- a/src/c/driver.c
+++ b/src/c/driver.c
@@ -189,6 +189,7 @@ static void *worker(void *data) {
printf("Serving URI %s....\n", path);
uw_set_headers(ctx, headers);
+ uw_write(ctx, "<html>");
while (1) {
if (uw_db_begin(ctx)) {
@@ -198,8 +199,8 @@ static void *worker(void *data) {
else {
fk = FATAL;
uw_reset(ctx);
- uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
- uw_write(ctx, "Content-type: text/plain\r\n\r\n");
+ uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
+ uw_write_header(ctx, "Content-type: text/plain\r\n\r\n");
uw_write(ctx, "Error running SQL BEGIN\n");
break;
@@ -212,13 +213,15 @@ static void *worker(void *data) {
strcpy(path_copy, path);
fk = uw_begin(ctx, path_copy);
if (fk == SUCCESS) {
+ uw_write(ctx, "</html>");
+
if (uw_db_commit(ctx)) {
fk = FATAL;
printf("Error running SQL COMMIT\n");
uw_reset(ctx);
- uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
- uw_write(ctx, "Content-type: text/plain\r\n\r\n");
+ uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
+ uw_write_header(ctx, "Content-type: text/plain\r\n");
uw_write(ctx, "Error running SQL COMMIT\n");
}
@@ -232,8 +235,8 @@ static void *worker(void *data) {
printf("Fatal error (out of retries): %s\n", uw_error_message(ctx));
uw_reset_keep_error_message(ctx);
- uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
- uw_write(ctx, "Content-type: text/plain\r\n\r\n");
+ uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
+ uw_write_header(ctx, "Content-type: text/plain\r\n");
uw_write(ctx, "Fatal error (out of retries): ");
uw_write(ctx, uw_error_message(ctx));
uw_write(ctx, "\n");
@@ -248,8 +251,8 @@ static void *worker(void *data) {
printf("Fatal error: %s\n", uw_error_message(ctx));
uw_reset_keep_error_message(ctx);
- uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
- uw_write(ctx, "Content-type: text/plain\r\n\r\n");
+ uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\r\n");
+ uw_write_header(ctx, "Content-type: text/plain\r\n");
uw_write(ctx, "Fatal error: ");
uw_write(ctx, uw_error_message(ctx));
uw_write(ctx, "\n");
@@ -261,8 +264,8 @@ static void *worker(void *data) {
printf("Unknown uw_handle return code!\n");
uw_reset_keep_request(ctx);
- uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
- uw_write(ctx, "Content-type: text/plain\r\n\r\n");
+ uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
+ uw_write_header(ctx, "Content-type: text/plain\r\n");
uw_write(ctx, "Unknown uw_handle return code!\n");
try_rollback(ctx);
diff --git a/src/c/urweb.c b/src/c/urweb.c
index be12c5ea..cc21c558 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -315,17 +315,7 @@ int uw_send(uw_context ctx, int sock) {
if (n < 0)
return n;
- n = uw_really_send(sock, "<html>", 6);
-
- if (n < 0)
- return n;
-
- n = uw_really_send(sock, ctx->page, ctx->page_front - ctx->page);
-
- if (n < 0)
- return n;
-
- return uw_really_send(sock, "</html>", 7);
+ return uw_really_send(sock, ctx->page, ctx->page_front - ctx->page);
}
static void uw_check_headers(uw_context ctx, size_t extra) {