cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdami...@apache.org
Subject svn commit: r1809062 - in /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon: reading/ResourceReader.java util/ByteRange.java
Date Wed, 20 Sep 2017 18:04:46 GMT
Author: cdamioli
Date: Wed Sep 20 18:04:45 2017
New Revision: 1809062

URL: http://svn.apache.org/viewvc?rev=1809062&view=rev
Log:
COCOON-2357 Content-Range and Range headers

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ResourceReader.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ByteRange.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ResourceReader.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ResourceReader.java?rev=1809062&r1=1809061&r2=1809062&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ResourceReader.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ResourceReader.java Wed
Sep 20 18:04:45 2017
@@ -275,17 +275,23 @@ public class ResourceReader extends Abst
         long contentLength = inputSource.getContentLength();
 
         if (byteRange != null) {
+            ByteRange actualByteRange = byteRange;
             String entityLength;
             String entityRange;
             if (contentLength != -1) {
                 entityLength = "" + contentLength;
-                entityRange = byteRange.intersection(new ByteRange(0, contentLength)).toString();
+                actualByteRange = byteRange.intersection(new ByteRange(0, contentLength -
1));
+                entityRange = actualByteRange.toString();
             } else {
                 entityLength = "*";
                 entityRange = byteRange.toString();
             }
 
-            response.setHeader("Content-Range", entityRange + "/" + entityLength);
+            response.setHeader("Content-Range", "bytes " + entityRange + "/" + entityLength);
+            
+            if (actualByteRange.length() != -1) {
+                response.setHeader("Content-Length", String.valueOf(actualByteRange.length()));
+            }
             if (response instanceof HttpResponse) {
                 // Response with status 206 (Partial content)
                 ((HttpResponse)response).setStatus(206);

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ByteRange.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ByteRange.java?rev=1809062&r1=1809061&r2=1809062&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ByteRange.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ByteRange.java Wed Sep 20
18:04:45 2017
@@ -67,6 +67,9 @@ final public class ByteRange {
 
     
     public long length() {
+        if (this.start == Long.MIN_VALUE || this.end == Long.MAX_VALUE) {
+            return -1;
+        }
         return this.end - this.start + 1;
     }
 



Mime
View raw message