# HG changeset patch # User Adam Chlipala # Date 1262457119 18000 # Node ID 7fc4e0087e500b451958fddd662f23c4b2928d8b # Parent 631a3597c065b0d09109e7ff5d32f7527fcaf70c Proper 404 generation diff -r 631a3597c065 -r 7fc4e0087e50 include/urweb.h --- a/include/urweb.h Fri Jan 01 12:48:06 2010 -0500 +++ b/include/urweb.h Sat Jan 02 13:31:59 2010 -0500 @@ -188,6 +188,7 @@ uw_Basis_string uw_Basis_requestHeader(uw_context, uw_Basis_string); void uw_write_header(uw_context, uw_Basis_string); +void uw_clear_headers(uw_context); uw_Basis_string uw_Basis_get_cookie(uw_context, uw_Basis_string c); uw_unit uw_Basis_set_cookie(uw_context, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v, uw_Basis_time *expires, uw_Basis_bool secure); diff -r 631a3597c065 -r 7fc4e0087e50 lib/ur/top.ur --- a/lib/ur/top.ur Fri Jan 01 12:48:06 2010 -0500 +++ b/lib/ur/top.ur Sat Jan 02 13:31:59 2010 -0500 @@ -246,6 +246,24 @@ return {acc}{r}) +fun queryX1' [nm ::: Name] [fs ::: {Type}] [ctx ::: {Unit}] [inp ::: {Type}] + (q : sql_query [nm = fs] []) + (f : $fs -> transaction (xml ctx inp [])) = + query q + (fn fs acc => + r <- f fs.nm; + return {acc}{r}) + + +fun queryXE' [exps ::: {Type}] [ctx ::: {Unit}] [inp ::: {Type}] + (q : sql_query [] exps) + (f : $exps -> transaction (xml ctx inp [])) = + query q + (fn fs acc => + r <- f fs; + return {acc}{r}) + + fun hasRows [tables ::: {{Type}}] [exps ::: {Type}] [tables ~ exps] (q : sql_query tables exps) = diff -r 631a3597c065 -r 7fc4e0087e50 lib/ur/top.urs --- a/lib/ur/top.urs Fri Jan 01 12:48:06 2010 -0500 +++ b/lib/ur/top.urs Sat Jan 02 13:31:59 2010 -0500 @@ -148,7 +148,15 @@ -> ($(exps ++ map (fn fields :: {Type} => $fields) tables) -> transaction (xml ctx inp [])) -> transaction (xml ctx inp []) - +val queryX1' : nm ::: Name -> fs ::: {Type} -> ctx ::: {Unit} -> inp ::: {Type} + -> sql_query [nm = fs] [] + -> ($fs -> transaction (xml ctx inp [])) + -> transaction (xml ctx inp []) +val queryXE' : exps ::: {Type} -> ctx ::: {Unit} -> inp ::: {Type} + -> sql_query [] exps + -> ($exps -> transaction (xml ctx inp [])) + -> transaction (xml ctx inp []) + val hasRows : tables ::: {{Type}} -> exps ::: {Type} -> [tables ~ exps] => sql_query tables exps diff -r 631a3597c065 -r 7fc4e0087e50 src/c/urweb.c --- a/src/c/urweb.c Fri Jan 01 12:48:06 2010 -0500 +++ b/src/c/urweb.c Sat Jan 02 13:31:59 2010 -0500 @@ -1174,6 +1174,10 @@ ctx->outHeaders.front += len; } +void uw_clear_headers(uw_context ctx) { + buf_reset(&ctx->outHeaders); +} + static void uw_check_script(uw_context ctx, size_t extra) { buf_check(&ctx->script, extra); } diff -r 631a3597c065 -r 7fc4e0087e50 src/cjr_print.sml --- a/src/cjr_print.sml Fri Jan 01 12:48:06 2010 -0500 +++ b/src/cjr_print.sml Sat Jan 02 13:31:59 2010 -0500 @@ -2833,7 +2833,11 @@ newline, p_list_sep newline (fn x => x) pds', newline, - string "uw_error(ctx, FATAL, \"Unknown page\");", + string "uw_clear_headers(ctx);", + newline, + string "uw_write_header(ctx, \"HTTP/1.1 404 Not Found\\r\\nContent-type: text/plain\\r\\n\");", + newline, + string "uw_write(ctx, \"Not Found\");", newline, string "}", newline,