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