httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1003839 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_disk_cache.xml modules/cache/mod_disk_cache.c modules/cache/mod_disk_cache.h
Date Sat, 02 Oct 2010 17:31:36 GMT
Author: minfrin
Date: Sat Oct  2 17:31:35 2010
New Revision: 1003839

URL: http://svn.apache.org/viewvc?rev=1003839&view=rev
Log:
mod_disk_cache: CacheMaxFileSize, CacheMinFileSize, CacheReadSize and 
CacheReadTime can be set per directory/location.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mod_disk_cache.xml
    httpd/httpd/trunk/modules/cache/mod_disk_cache.c
    httpd/httpd/trunk/modules/cache/mod_disk_cache.h

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1003839&r1=1003838&r2=1003839&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Sat Oct  2 17:31:35 2010
@@ -6,6 +6,9 @@ Changes with Apache 2.3.9
      Fix a denial of service attack against mod_reqtimeout.
      [Stefan Fritsch]
 
+  *) mod_disk_cache: CacheMaxFileSize, CacheMinFileSize, CacheReadSize and
+     CacheReadTime can be set per directory/location. [Graham Leggett]
+
   *) core: Speed up config parsing if using a very large number of config
      files. PR 50002 [andrew cloudaccess net]
 

Modified: httpd/httpd/trunk/docs/manual/mod/mod_disk_cache.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_disk_cache.xml?rev=1003839&r1=1003838&r2=1003839&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_disk_cache.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_disk_cache.xml Sat Oct  2 17:31:35 2010
@@ -141,7 +141,10 @@ cache.</description>
 cache</description>
 <syntax>CacheMinFileSize <var>bytes</var></syntax>
 <default>CacheMinFileSize 1</default>
-<contextlist><context>server config</context><context>virtual host</context>
+<contextlist><context>server config</context>
+  <context>virtual host</context>
+  <context>directory</context>
+  <context>.htaccess</context>
 </contextlist>
 
 <usage>
@@ -161,9 +164,12 @@ cache</description>
 cache</description>
 <syntax>CacheMaxFileSize <var>bytes</var></syntax>
 <default>CacheMaxFileSize 1000000</default>
-<contextlist><context>server config</context><context>virtual host</context>
+<contextlist><context>server config</context>
+  <context>virtual host</context>
+  <context>directory</context>
+  <context>.htaccess</context>
 </contextlist>
-
+  
 <usage>
     <p>The <directive>CacheMaxFileSize</directive> directive sets the
     maximum size, in bytes, for a document to be considered for storage in

Modified: httpd/httpd/trunk/modules/cache/mod_disk_cache.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_disk_cache.c?rev=1003839&r1=1003838&r2=1003839&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_disk_cache.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_disk_cache.c Sat Oct  2 17:31:35 2010
@@ -335,6 +335,7 @@ static void tokens_to_array(apr_pool_t *
 static int create_entity(cache_handle_t *h, request_rec *r, const char *key, apr_off_t len,
                          apr_bucket_brigade *bb)
 {
+    disk_cache_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &disk_cache_module);
     disk_cache_conf *conf = ap_get_module_config(r->server->module_config,
                                                  &disk_cache_module);
     cache_object_t *obj;
@@ -354,18 +355,18 @@ static int create_entity(cache_handle_t 
     }
 
     /* Note, len is -1 if unknown so don't trust it too hard */
-    if (len > conf->maxfs) {
+    if (len > dconf->maxfs) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                      "disk_cache: URL %s failed the size check "
                      "(%" APR_OFF_T_FMT " > %" APR_OFF_T_FMT ")",
-                     key, len, conf->maxfs);
+                     key, len, dconf->maxfs);
         return DECLINED;
     }
-    if (len >= 0 && len < conf->minfs) {
+    if (len >= 0 && len < dconf->minfs) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                      "disk_cache: URL %s failed the size check "
                      "(%" APR_OFF_T_FMT " < %" APR_OFF_T_FMT ")",
-                     key, len, conf->minfs);
+                     key, len, dconf->minfs);
         return DECLINED;
     }
 
@@ -1172,11 +1173,11 @@ static apr_status_t store_body(cache_han
             return rv;
         }
         dobj->file_size += written;
-        if (dobj->file_size > conf->maxfs) {
+        if (dobj->file_size > dconf->maxfs) {
             ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                          "disk_cache: URL %s failed the size check "
                          "(%" APR_OFF_T_FMT ">%" APR_OFF_T_FMT ")",
-                         h->cache_obj->key, dobj->file_size, conf->maxfs);
+                         h->cache_obj->key, dobj->file_size, dconf->maxfs);
             /* Remove the intermediate cache file and return non-APR_SUCCESS */
             apr_pool_destroy(dobj->data.pool);
             APR_BRIGADE_CONCAT(out, dobj->bb);
@@ -1221,11 +1222,11 @@ static apr_status_t store_body(cache_han
             apr_pool_destroy(dobj->data.pool);
             return APR_EGENERAL;
         }
-        if (dobj->file_size < conf->minfs) {
+        if (dobj->file_size < dconf->minfs) {
             ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                          "disk_cache: URL %s failed the size check "
                          "(%" APR_OFF_T_FMT "<%" APR_OFF_T_FMT ")",
-                         h->cache_obj->key, dobj->file_size, conf->minfs);
+                         h->cache_obj->key, dobj->file_size, dconf->minfs);
             /* Remove the intermediate cache file and return non-APR_SUCCESS */
             apr_pool_destroy(dobj->data.pool);
             return APR_EGENERAL;
@@ -1291,6 +1292,8 @@ static void *create_dir_config(apr_pool_
 {
     disk_cache_dir_conf *dconf = apr_pcalloc(p, sizeof(disk_cache_dir_conf));
 
+    dconf->maxfs = DEFAULT_MAX_FILE_SIZE;
+    dconf->minfs = DEFAULT_MIN_FILE_SIZE;
     dconf->readsize = DEFAULT_READSIZE;
     dconf->readtime = DEFAULT_READTIME;
 
@@ -1302,6 +1305,10 @@ static void *merge_dir_config(apr_pool_t
     disk_cache_dir_conf *add = (disk_cache_dir_conf *) addv;
     disk_cache_dir_conf *base = (disk_cache_dir_conf *) basev;
 
+    new->maxfs = (add->maxfs_set == 0) ? base->maxfs : add->maxfs;
+    new->maxfs_set = add->maxfs_set || base->maxfs_set;
+    new->minfs = (add->minfs_set == 0) ? base->minfs : add->minfs;
+    new->minfs_set = add->minfs_set || base->minfs_set;
     new->readsize = (add->readsize_set == 0) ? base->readsize : add->readsize;
     new->readsize_set = add->readsize_set || base->readsize_set;
     new->readtime = (add->readtime_set == 0) ? base->readtime : add->readtime;
@@ -1317,8 +1324,6 @@ static void *create_config(apr_pool_t *p
     /* XXX: Set default values */
     conf->dirlevels = DEFAULT_DIRLEVELS;
     conf->dirlength = DEFAULT_DIRLENGTH;
-    conf->maxfs = DEFAULT_MAX_FILE_SIZE;
-    conf->minfs = DEFAULT_MIN_FILE_SIZE;
 
     conf->cache_root = NULL;
     conf->cache_root_len = 0;
@@ -1378,11 +1383,10 @@ static const char
 static const char
 *set_cache_minfs(cmd_parms *parms, void *in_struct_ptr, const char *arg)
 {
-    disk_cache_conf *conf = ap_get_module_config(parms->server->module_config,
-                                                 &disk_cache_module);
+    disk_cache_dir_conf *dconf = (disk_cache_dir_conf *)in_struct_ptr;
 
-    if (apr_strtoff(&conf->minfs, arg, NULL, 0) != APR_SUCCESS ||
-            conf->minfs < 0) 
+    if (apr_strtoff(&dconf->minfs, arg, NULL, 0) != APR_SUCCESS ||
+            dconf->minfs < 0)
     {
         return "CacheMinFileSize argument must be a non-negative integer representing the
min size of a file to cache in bytes.";
     }
@@ -1392,10 +1396,10 @@ static const char
 static const char
 *set_cache_maxfs(cmd_parms *parms, void *in_struct_ptr, const char *arg)
 {
-    disk_cache_conf *conf = ap_get_module_config(parms->server->module_config,
-                                                 &disk_cache_module);
-    if (apr_strtoff(&conf->maxfs, arg, NULL, 0) != APR_SUCCESS ||
-            conf->maxfs < 0) 
+    disk_cache_dir_conf *dconf = (disk_cache_dir_conf *)in_struct_ptr;
+
+    if (apr_strtoff(&dconf->maxfs, arg, NULL, 0) != APR_SUCCESS ||
+            dconf->maxfs < 0)
     {
         return "CacheMaxFileSize argument must be a non-negative integer representing the
max size of a file to cache in bytes.";
     }
@@ -1440,13 +1444,13 @@ static const command_rec disk_cache_cmds
                   "The number of levels of subdirectories in the cache"),
     AP_INIT_TAKE1("CacheDirLength", set_cache_dirlength, NULL, RSRC_CONF,
                   "The number of characters in subdirectory names"),
-    AP_INIT_TAKE1("CacheMinFileSize", set_cache_minfs, NULL, RSRC_CONF,
+    AP_INIT_TAKE1("CacheMinFileSize", set_cache_minfs, NULL, RSRC_CONF | ACCESS_CONF,
                   "The minimum file size to cache a document"),
-    AP_INIT_TAKE1("CacheMaxFileSize", set_cache_maxfs, NULL, RSRC_CONF,
+    AP_INIT_TAKE1("CacheMaxFileSize", set_cache_maxfs, NULL, RSRC_CONF | ACCESS_CONF,
                   "The maximum file size to cache a document"),
-    AP_INIT_TAKE1("CacheReadSize", set_cache_readsize, NULL, RSRC_CONF,
+    AP_INIT_TAKE1("CacheReadSize", set_cache_readsize, NULL, RSRC_CONF | ACCESS_CONF,
                   "The maximum quantity of data to attempt to read and cache in one go"),
-    AP_INIT_TAKE1("CacheReadTime", set_cache_readtime, NULL, RSRC_CONF,
+    AP_INIT_TAKE1("CacheReadTime", set_cache_readtime, NULL, RSRC_CONF | ACCESS_CONF,
                   "The maximum time taken to attempt to read and cache in go"),
     {NULL}
 };

Modified: httpd/httpd/trunk/modules/cache/mod_disk_cache.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_disk_cache.h?rev=1003839&r1=1003838&r2=1003839&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_disk_cache.h (original)
+++ httpd/httpd/trunk/modules/cache/mod_disk_cache.h Sat Oct  2 17:31:35 2010
@@ -109,13 +109,15 @@ typedef struct {
     apr_size_t cache_root_len;
     int dirlevels;               /* Number of levels of subdirectories */
     int dirlength;               /* Length of subdirectory names */
-    apr_off_t minfs;             /* minimum file size for cached files */
-    apr_off_t maxfs;             /* maximum file size for cached files */
 } disk_cache_conf;
 
 typedef struct {
+    apr_off_t minfs;             /* minimum file size for cached files */
+    apr_off_t maxfs;             /* maximum file size for cached files */
     apr_off_t readsize;          /* maximum data to attempt to cache in one go */
     apr_time_t readtime;         /* maximum time taken to cache in one go */
+    int minfs_set;
+    int maxfs_set;
     int readsize_set;
     int readtime_set;
 } disk_cache_dir_conf;



Mime
View raw message