2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: file.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
14 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
15 let name = q#param "name" in
17 try Some (int_of_string (q#param "version")) with Not_found -> None in
19 (* Get the file and its MIME type. *)
22 None -> "hostid = ? and name = ?", [`Int hostid; `String name]
24 "hostid = ? and (name = ? or name_deleted = ?) and id = ?",
25 [`Int hostid; `String name; `String name; `Int version] in
28 dbh#prepare_cached ("select content, mime_type from files
33 match sth#fetch1 () with
34 [ `Binary data; `String mime_type ] ->
36 | _ -> assert false in
38 if version <> None then
39 (* Set a medium-length expiry time on this resource. *)
40 Table.set (Request.headers_out r) "Expires" (Cgi_expires.expires_medium());
42 q#header ~content_type:mime_type ();