]> granicus.if.org Git - apache/commitdiff
take care of some MaxRanges feedback:
authorEric Covener <covener@apache.org>
Wed, 7 Sep 2011 17:29:49 +0000 (17:29 +0000)
committerEric Covener <covener@apache.org>
Wed, 7 Sep 2011 17:29:49 +0000 (17:29 +0000)
 * allow "none" to be expressed in config
 * send Accept-Ranges: none with MaxRanges none
 * stop accepting confusing/ambiguous "0", start accepting "unlimited".

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1166282 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/core.xml
include/http_core.h
modules/http/byterange_filter.c
server/core.c

diff --git a/CHANGES b/CHANGES
index e0e54475d5d37d446aeb67ed4fa0dc7750961ef6..a79db2f8c295cb7ef2b382e3392a3b9cabc62c42 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,10 @@ Changes with Apache 2.3.15
      the original file, ignore the ranges and send the complete file.
      PR 51714. [Stefan Fritsch, Jim Jagielski, Ruediger Pluem, Eric Covener]
 
+  *) core: Allow MaxRanges none|unlimited|default and set 'Accept-Ranges: none'
+     in the case Ranges are being ignored with MaxRanges none.
+     [Eric Covener]
+
   *) mod_ssl: revamp CRL-based revocation checking when validating
      certificates of clients or proxied servers. Completely delegate
      CRL processing to OpenSSL, and add a new [Proxy]CARevocationCheck
index a6956be99b7b18f5747e9776c06d106605dc394e..4c7bda7ce483c36fc7ac07fd1d8495df20042595 100644 (file)
@@ -2869,7 +2869,7 @@ connection</description>
 <name>MaxRanges</name>
 <description>Number of ranges allowed before returning the complete
 resource </description>
-<syntax>MaxRanges <var>number</var> (0 = no limit)</syntax>
+<syntax>MaxRanges default | unlimited | none | <var>number-of-ranges</var></syntax>
 <default>MaxRanges 200</default>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context>
@@ -2881,6 +2881,22 @@ resource </description>
     limits the number of HTTP ranges the server is willing to 
     return to the client.  If more ranges then permitted are requested, 
     the complete resource is returned instead.</p>
+
+    <dl>  
+      <dt><strong>default</strong></dt>
+      <dd>Limits the number of ranges to a compile-time default of 200.</dd>
+   
+      <dt><strong>none</strong></dt>
+      <dd>Range headers are ignored.</dd>
+          
+      <dt><strong>unlimited</strong></dt>
+      <dd>The server does not limit the number of ranges it is
+          willing to satisfy.</dd>
+
+      <dt><var>number-of-ranges</var></dt>
+      <dd>A positive number representing the maximum number of ranges the
+      server is willing to satisfy.</dd>
+    </dl>
 </usage>
 </directivesynopsis>
 
index cfd7cf08fb1163529c1950ed1817fab1af6e5791..4c1da18cfecd3ba8b3e96bd0f6650e83fe9070ec 100644 (file)
@@ -605,7 +605,11 @@ typedef struct {
     /** Table of directives allowed per AllowOverrideList */
     apr_table_t *override_list;
 
-    /** Number of Ranges before returning HTTP_OK, 0/unlimited -1/unset. **/
+#define AP_MAXRANGES_UNSET     -1
+#define AP_MAXRANGES_DEFAULT   -2
+#define AP_MAXRANGES_UNLIMITED -3
+#define AP_MAXRANGES_NORANGES   0
+    /** Number of Ranges before returning HTTP_OK. **/
     int max_ranges;
 
 } core_dir_config;
index de6c729fdfcd294423d4e35d52b20070619164ef..350017b0bda39277c19feaf20ae069b52cc3d20e 100644 (file)
@@ -192,7 +192,12 @@ typedef struct indexes_t {
 
 static int get_max_ranges(request_rec *r) { 
     core_dir_config *core_conf = ap_get_core_module_config(r->per_dir_config);
-    return core_conf->max_ranges == -1 ? DEFAULT_MAX_RANGES : core_conf->max_ranges;
+    if (core_conf->max_ranges >= 0 || core_conf->max_ranges == AP_MAXRANGES_UNLIMITED) { 
+        return core_conf->max_ranges;
+    }
+
+    /* Any other negative val means the default */
+    return DEFAULT_MAX_RANGES;
 }
 
 static apr_status_t send_416(ap_filter_t *f, apr_bucket_brigade *tmpbb)
@@ -257,7 +262,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f,
     num_ranges = ap_set_byterange(r, clength, &indexes);
 
     /* We have nothing to do, get out of the way. */
-    if (num_ranges == 0 || (max_ranges > 0 && num_ranges > max_ranges)) {
+    if (num_ranges == 0 || (max_ranges >= 0 && num_ranges > max_ranges)) {
         r->status = original_status;
         ap_remove_output_filter(f);
         return ap_pass_brigade(f->next, bb);
index a6ac9c11efcb270b310e9ded66abac18b880e1c4..632b15d5d9574bf4949e1737a416ff56364c935f 100644 (file)
@@ -179,7 +179,7 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir)
     conf->allow_encoded_slashes = 0;
     conf->decode_encoded_slashes = 0;
  
-    conf->max_ranges = -1;
+    conf->max_ranges = AP_MAXRANGES_UNSET;
 
     return (void *)conf;
 }
@@ -399,7 +399,7 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
         }
     }
 
-    conf->max_ranges = new->max_ranges != -1 ? new->max_ranges : base->max_ranges;
+    conf->max_ranges = new->max_ranges != AP_MAXRANGES_UNSET ? new->max_ranges : base->max_ranges;
 
     return (void*)conf;
 }
@@ -3267,11 +3267,26 @@ static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_,
 static const char *set_max_ranges(cmd_parms *cmd, void *conf_, const char *arg)
 {
     core_dir_config *conf = conf_;
+    int val = 0;
 
-    conf->max_ranges = atoi(arg);
-    if (conf->max_ranges < 0)
-        return "MaxRanges requires a non-negative integer (0 = unlimited)";
+    if (!strcasecmp(arg, "none")) { 
+        val = AP_MAXRANGES_NORANGES;
+    }
+    else if (!strcasecmp(arg, "default")) { 
+        val = AP_MAXRANGES_DEFAULT;
+    }
+    else if (!strcasecmp(arg, "unlimited")) { 
+        val = AP_MAXRANGES_UNLIMITED;
+    }
+    else { 
+        val = atoi(arg);
+        if (val <= 0)
+            return "MaxRanges requires 'none', 'default', 'unlimited' or " 
+                   "a positive integer";
+    }
 
+    conf->max_ranges = val;
+    
     return NULL;
 }
 AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r)
@@ -4196,7 +4211,9 @@ static int default_handler(request_rec *r)
         ap_update_mtime(r, r->finfo.mtime);
         ap_set_last_modified(r);
         ap_set_etag(r);
-        apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
+        apr_table_setn(r->headers_out, "Accept-Ranges", 
+                       (d->max_ranges == AP_MAXRANGES_NORANGES) ? "none" 
+                                                                : "bytes");
         ap_set_content_length(r, r->finfo.size);
         if (bld_content_md5) {
             apr_table_setn(r->headers_out, "Content-MD5",