1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
constant cvs_version = "$Id$"; 
constant thread_safe = 1; 
 
#include <module.h> 
inherit "module"; 
 
constant module_type = MODULE_FILTER; 
constant module_name = "Expires modifier"; 
constant module_doc  = "Adds expires header of configurable time " 
                           "to selected files."; 
constant module_unique = 0;  
 
array(string) globs; 
int expire_time; 
 
void create() 
{ 
  defvar("paths", 
         Variable.StringList(({}), VAR_INITIAL, 
                             "Path globs", #"\ 
<p>List of glob expressions for files that should be targeted for 
modification of the expire time, e.g. 
<tt>/images/navigation/*.gif</tt>. The glob chars '?' and '*' match 
any character, including '/'.</p> 
 
<p>Try to keep this to a minimum in order to minimize performance 
issues and avoid overcaching of other files.</p>")); 
 
  defvar("expire_time", INITIAL_CACHEABLE, 
         "Expire time", TYPE_INT, 
         "The number of seconds the files should expire in. " 
         "Leaving this to the default value might result in that no 'Expire:' " 
         "header at all is sent to the client and should be used to " 
         "compensate for other modules that has previously lowered the " 
         "expire time."); 
} 
 
void start(int when, Configuration conf) 
{ 
  globs = query("paths"); 
  expire_time = query("expire_time"); 
} 
 
mapping|void filter(mapping res, RequestID id) 
{ 
  if (!res) return; 
 
  foreach(globs, string g) { 
    if (glob(g, id->not_query)) { 
 
#ifdef DEBUG_CACHEABLE 
      report_debug("Original extra_heads: %O\n", res->extra_heads); 
#endif 
       
      if (res->extra_heads) { 
        m_delete(res->extra_heads, "cache-control"); 
        m_delete(res->extra_heads, "Cache-Control"); 
        m_delete(res->extra_heads, "expires"); 
        m_delete(res->extra_heads, "Expires"); 
      } 
       
      RAISE_CACHE(expire_time); 
 
      id->misc->vary = (<>); 
 
#ifdef DEBUG_CACHEABLE 
      report_debug("Rewrote extra_heads: %O\n", res->extra_heads); 
#endif 
 
      return res; 
    } 
  } 
}