Logging in and logging out.
[cocanwiki.git] / scripts / cgi_expires.ml
1 (* COCANWIKI scripts.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: cgi_expires.ml,v 1.2 2004/09/07 14:58:34 rich Exp $
5  *)
6
7 open Apache
8 open Registry
9 open Cgi
10
11 open Printf
12
13 open Cocanwiki_date
14
15 (* This library should eventually be integrated with mod_caml. XXX *)
16
17 (* Expires headers.
18  *
19  * All content on wiki sites is dynamic, but we try to make it look static
20  * for users and search engines.  We have 4 types of 'Expires' headers that
21  * we can send:
22  *
23  * expires_past ()
24  *   Send an expiry header in the past (theoretically removing content from
25  *   caches).
26  * expires_short ()
27  *   Send a short expiry header (now + 5 minutes).  This should be used for
28  *   all news pages.
29  * expires_medium ()
30  *   Send a medium-term expiry header (now + 24 hours).  This should be used
31  *   for all "static" content.
32  * expires_long ()
33  *   Send a very long expiry header (now + 2 years).  This should be used for
34  *   content which really never will change.
35  *)
36 let expires_past, expires_short, expires_medium, expires_long =
37   let make offset =
38     let t = Unix.time () in
39     let tm = Unix.gmtime (t +. float offset) in
40     sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT"
41       (short_weekday tm.Unix.tm_wday)
42       tm.Unix.tm_mday
43       (short_month (tm.Unix.tm_mon + 1))
44       (tm.Unix.tm_year + 1900)
45       tm.Unix.tm_hour
46       tm.Unix.tm_min
47       tm.Unix.tm_sec
48   in
49   let mins m = m * 60 in
50   let days d = d * 86400 in
51   (fun () -> make (mins (-5))),
52   (fun () -> make (mins 5)),
53   (fun () -> make (days 1)),
54   (fun () -> make (days (365*2)))