# HG changeset patch # User Adam Chlipala # Date 1225992170 18000 # Node ID 91914c15a85bd61fbcc38733c5bffb3b4775b872 # Parent bb27c7efcd905566ec904da05c0ddfc5d80f2f76 Cookie demo code; fix error message display diff -r bb27c7efcd90 -r 91914c15a85b demo/cookie.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/cookie.ur Thu Nov 06 12:22:50 2008 -0500 @@ -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 Cookie set. + +fun main () = + ro <- getCookie c; + let + val xml = case ro of + None => No cookie set. + | Some v => Cookie: A = {[v.A]}, B = {[v.B]}, C = {[v.C]} + in + return + {xml}

+ +
+ A:
+ B:
+ C:
+ + +
+ end + + diff -r bb27c7efcd90 -r 91914c15a85b demo/cookie.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/cookie.urp Thu Nov 06 12:22:50 2008 -0500 @@ -0,0 +1,2 @@ + +cookie diff -r bb27c7efcd90 -r 91914c15a85b demo/cookie.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/cookie.urs Thu Nov 06 12:22:50 2008 -0500 @@ -0,0 +1,1 @@ +val main : unit -> transaction page diff -r bb27c7efcd90 -r 91914c15a85b src/c/driver.c --- a/src/c/driver.c Thu Nov 06 12:08:41 2008 -0500 +++ b/src/c/driver.c Thu Nov 06 12:22:50 2008 -0500 @@ -189,6 +189,7 @@ printf("Serving URI %s....\n", path); uw_set_headers(ctx, headers); + uw_write(ctx, ""); while (1) { if (uw_db_begin(ctx)) { @@ -198,8 +199,8 @@ 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 @@ strcpy(path_copy, path); fk = uw_begin(ctx, path_copy); if (fk == SUCCESS) { + uw_write(ctx, ""); + 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 @@ 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 @@ 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 @@ 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 -r bb27c7efcd90 -r 91914c15a85b src/c/urweb.c --- a/src/c/urweb.c Thu Nov 06 12:08:41 2008 -0500 +++ b/src/c/urweb.c Thu Nov 06 12:22:50 2008 -0500 @@ -315,17 +315,7 @@ if (n < 0) return n; - n = uw_really_send(sock, "", 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, "", 7); + return uw_really_send(sock, ctx->page, ctx->page_front - ctx->page); } static void uw_check_headers(uw_context ctx, size_t extra) {