Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45419
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 17 Sep 2008 19:26:22 +0000 (19:26 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 17 Sep 2008 19:26:22 +0000 (19:26 +0000)
Set the Accept-Ranges header on content served from the DefaultServlet. This can be disabled via configuration if required.

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

conf/web.xml
java/org/apache/catalina/servlets/DefaultServlet.java
webapps/docs/default-servlet.xml

index 88e9f49..9c7d344 100644 (file)
@@ -70,6 +70,9 @@
   <!--                       which sendfile will be used. Use a negative    -->
   <!--                       value to always disable sendfile.  [48]        -->
   <!--                                                                      -->
+  <!--   useAcceptRanges     Should the Accept-Ranges header be included    -->
+  <!--                       in responses where appropriate? [true]         -->
+  <!--                                                                      -->
   <!--  For directory listing customization. Checks localXsltFile, then     -->
   <!--  globalXsltFile, then defaults to original behavior.                 -->
   <!--                                                                      -->
index c6bd34b..fc38923 100644 (file)
@@ -154,7 +154,11 @@ public class DefaultServlet
      */
     protected int sendfileSize = 48 * 1024;
     
-    
+    /**
+     * Should the Accept-Ranges: bytes header be send with static resources?
+     */
+    protected boolean useAcceptRanges = true;
+
     /**
      * Full range marker.
      */
@@ -241,6 +245,9 @@ public class DefaultServlet
         localXsltFile = getServletConfig().getInitParameter("localXsltFile");
         readmeFile = getServletConfig().getInitParameter("readmeFile");
 
+        if (getServletConfig().getInitParameter("useAcceptRanges") != null)
+            useAcceptRanges = Boolean.parseBoolean(getServletConfig().getInitParameter("useAcceptRanges"));
+
         // Sanity check on the specified buffer sizes
         if (input < 256)
             input = 256;
@@ -717,9 +724,12 @@ public class DefaultServlet
             contentType = "text/html;charset=UTF-8";
 
         } else {
+            if (useAcceptRanges) {
+                // Accept ranges header
+                response.setHeader("Accept-Ranges", "bytes");
+            }
 
             // Parse range specifier
-
             ranges = parseRange(request, response, cacheEntry.attributes);
 
             // ETag header
index 75e8f93..914c2b9 100644 (file)
@@ -179,6 +179,13 @@ The DefaultServlet allows the following initParamters:
         to always disable sendfile. [48]
     </td>
   </tr>
+  <tr>
+    <th valign='top'>useAcceptRanges</th>
+    <td valign='top'>
+        If true, the Accept-Ranges header will be set when appropriate for the
+        response. [true]
+    </td>
+  </tr>
 
 </table>
 </section>