Added a "name" field to the mailing list entries.
[cocanwiki.git] / scripts / cgi_expires.ml
1 (* COCANWIKI - a wiki written in Objective CAML.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: cgi_expires.ml,v 1.3 2004/09/09 12:21:22 rich Exp $
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *)
21
22 open Apache
23 open Registry
24 open Cgi
25
26 open Printf
27
28 open Cocanwiki_date
29
30 (* This library should eventually be integrated with mod_caml. XXX *)
31
32 (* Expires headers.
33  *
34  * All content on wiki sites is dynamic, but we try to make it look static
35  * for users and search engines.  We have 4 types of 'Expires' headers that
36  * we can send:
37  *
38  * expires_past ()
39  *   Send an expiry header in the past (theoretically removing content from
40  *   caches).
41  * expires_short ()
42  *   Send a short expiry header (now + 5 minutes).  This should be used for
43  *   all news pages.
44  * expires_medium ()
45  *   Send a medium-term expiry header (now + 24 hours).  This should be used
46  *   for all "static" content.
47  * expires_long ()
48  *   Send a very long expiry header (now + 2 years).  This should be used for
49  *   content which really never will change.
50  *)
51 let expires_past, expires_short, expires_medium, expires_long =
52   let make offset =
53     let t = Unix.time () in
54     let tm = Unix.gmtime (t +. float offset) in
55     sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT"
56       (short_weekday tm.Unix.tm_wday)
57       tm.Unix.tm_mday
58       (short_month (tm.Unix.tm_mon + 1))
59       (tm.Unix.tm_year + 1900)
60       tm.Unix.tm_hour
61       tm.Unix.tm_min
62       tm.Unix.tm_sec
63   in
64   let mins m = m * 60 in
65   let days d = d * 86400 in
66   (fun () -> make (mins (-5))),
67   (fun () -> make (mins 5)),
68   (fun () -> make (days 1)),
69   (fun () -> make (days (365*2)))