Moved to merjis/tools/wiki.
[cocanwiki.git] / scripts / hoststyle.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: hoststyle.ml,v 1.1 2004/09/07 10:14:09 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10 open Printf
11
12 open Cocanwiki
13
14 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _) _ =
15   (* Get the CSS. *)
16   let sth = dbh#prepare_cached "select css from hosts where id = ?" in
17   sth#execute [`Int hostid];
18
19   let css =
20     match sth#fetch1 () with
21         [ `Null ] -> ""
22       | [ `String css ] -> css
23       | _ -> assert false in
24
25   (* It's crucial, for speed of page delivery and rendering, to have
26    * an expires header for CSS.  Even though this means that occasionally
27    * people will need to hit [Shift]+Reload, I'm going to set a
28    * medium-length expiry time on this resource.
29    *)
30   Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium ());
31
32   q#header ~content_type:"text/css" ();
33   print_string r css
34
35 let () =
36   register_script run