changeset 1110:7fc4e0087e50

Proper 404 generation
author Adam Chlipala <adamc@hcoop.net>
date Sat, 02 Jan 2010 13:31:59 -0500
parents 631a3597c065
children e1d738870086
files include/urweb.h lib/ur/top.ur lib/ur/top.urs src/c/urweb.c src/cjr_print.sml
diffstat 5 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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 <xml>{acc}{r}</xml>)
           <xml/>
 
+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 <xml>{acc}{r}</xml>)
+          <xml/>
+
+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 <xml>{acc}{r}</xml>)
+          <xml/>
+
 fun hasRows [tables ::: {{Type}}] [exps ::: {Type}]
             [tables ~ exps]
             (q : sql_query tables exps) =
--- 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
--- 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);
 }
--- 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,