chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1363387 - /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
Date Thu, 19 Jul 2012 15:39:22 GMT
Author: fmui
Date: Thu Jul 19 15:39:22 2012
New Revision: 1363387

URL: http://svn.apache.org/viewvc?rev=1363387&view=rev
Log:
CMIS 556:  server fixes

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java?rev=1363387&r1=1363386&r2=1363387&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
Thu Jul 19 15:39:22 2012
@@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.se
 import java.io.File;
 import java.lang.reflect.Method;
 import java.math.BigInteger;
+import java.util.Locale;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
@@ -79,33 +80,38 @@ public class HttpUtils {
         // decode range
         String rangeHeader = request.getHeader("Range");
         if (rangeHeader != null) {
-            rangeHeader = rangeHeader.trim();
-            BigInteger offset = null;
-            BigInteger length = null;
-
-            int eq = rangeHeader.indexOf('=');
-            int ds = rangeHeader.indexOf('-');
-            if ((eq > 0) && (ds > eq)) {
-                String offsetStr = rangeHeader.substring(eq + 1, ds).trim();
-                if (offsetStr.length() > 0) {
-                    offset = new BigInteger(offsetStr);
-                }
+            rangeHeader = rangeHeader.trim().toLowerCase(Locale.ENGLISH);
 
-                if (ds < rangeHeader.length()) {
-                    String lengthStr = rangeHeader.substring(ds + 1).trim();
-                    if (lengthStr.length() > 0) {
-                        if (offset == null) {
-                            length = new BigInteger(lengthStr);
-                        } else {
-                            length = (new BigInteger(lengthStr)).subtract(offset);
+            if (rangeHeader.length() > 6 && rangeHeader.startsWith("bytes=") &&
rangeHeader.indexOf(',') == -1
+                    && rangeHeader.charAt(6) != '-') {
+                BigInteger offset = null;
+                BigInteger length = null;
+
+                int ds = rangeHeader.indexOf('-');
+                if (ds > 6) {
+                    try {
+                        String firstBytePosStr = rangeHeader.substring(6, ds);
+                        if (firstBytePosStr.length() > 0) {
+                            offset = new BigInteger(firstBytePosStr);
                         }
-                    }
 
-                    if (offset != null) {
-                        context.put(CallContext.OFFSET, offset);
-                    }
-                    if (length != null) {
-                        context.put(CallContext.LENGTH, length);
+                        if (!rangeHeader.endsWith("-")) {
+                            String lastBytePosStr = rangeHeader.substring(ds + 1);
+                            if (offset == null) {
+                                length = (new BigInteger(lastBytePosStr)).add(BigInteger.ONE);
+                            } else {
+                                length = (new BigInteger(lastBytePosStr)).subtract(offset).add(BigInteger.ONE);
+                            }
+                        }
+
+                        if (offset != null) {
+                            context.put(CallContext.OFFSET, offset);
+                        }
+                        if (length != null) {
+                            context.put(CallContext.LENGTH, length);
+                        }
+                    } catch (NumberFormatException e) {
+                        // invalid Range header must be ignored
                     }
                 }
             }



Mime
View raw message