diff src/cjr_print.sml @ 1263:be2ef50780ed

Support HTTP caching of app.js
author Adam Chlipala <adamc@hcoop.net>
date Sun, 23 May 2010 11:52:13 -0400
parents fd1a49b51db5
children 514be09d5018
line wrap: on
line diff
--- a/src/cjr_print.sml	Sat May 22 16:29:54 2010 -0400
+++ b/src/cjr_print.sml	Sun May 23 11:52:13 2010 -0400
@@ -2780,8 +2780,17 @@
                  newline]
 
         val initializers = List.mapPartial (fn (DTask (Initialize, e), _) => SOME e | _ => NONE) ds
+
+        val now = Time.now ()
+        val nowD = Date.fromTimeUniv now
+        val rfcFmt = "%a, %d %b %Y %H:%M:%S"
     in
-        box [string "#include <stdio.h>",
+        box [string "#include \"",
+             string (OS.Path.joinDirFile {dir = Config.includ,
+                                          file = "config.h"}),
+             string "\"",
+             newline,
+             string "#include <stdio.h>",
              newline,
              string "#include <stdlib.h>",
              newline,
@@ -2789,6 +2798,8 @@
              newline,
              string "#include <math.h>",
              newline,
+             string "#include <time.h>",
+             newline,
              if hasDb then
                  box [string ("#include <" ^ #header (Settings.currentDbms ()) ^ ">"),
                       newline]
@@ -2875,7 +2886,22 @@
                                           file = "app.js"}),
              string "\")) {",
              newline,
-             box [string "uw_write_header(ctx, \"Content-type: text/javascript\\r\\n\");",
+             box [string "uw_Basis_string ims = uw_Basis_requestHeader(ctx, \"If-modified-since\");",
+                  newline,
+                  string ("if (ims && !strcmp(ims, \"" ^ Date.fmt rfcFmt nowD ^ "\")) {"),
+                  newline,
+                  box [string "uw_clear_headers(ctx);",
+                       newline,
+                       string "uw_write_header(ctx, \"HTTP/1.1 304 Not Modified\\r\\n\");",
+                       newline,
+                       string "return;",
+                       newline],
+                  string "}",
+                  newline,
+                  newline,
+                  string "uw_write_header(ctx, \"Content-type: text/javascript\\r\\n\");",
+                  newline,
+                  string ("uw_write_header(ctx, \"Last-modified: " ^ Date.fmt rfcFmt nowD ^ "\\r\\n\");"),
                   newline,
                   string "uw_write(ctx, jslib);",
                   newline,