incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1541131 - in /sling/trunk/bundles/servlets/post/src: main/java/org/apache/sling/servlets/post/impl/helper/MediaRangeList.java test/java/org/apache/sling/servlets/post/impl/helper/MediaRangeListTest.java
Date Tue, 12 Nov 2013 16:30:17 GMT
Author: chetanm
Date: Tue Nov 12 16:30:16 2013
New Revision: 1541131

URL: http://svn.apache.org/r1541131
Log:
SLING-3175 - Make MediaRange parser linient to accept invalid Accept header generated by Oracle
JDK HttpUrlConnection

Relaxing the parsing logic for type/subtype to allow handling of header like
`text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2`

Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/MediaRangeList.java
    sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/MediaRangeListTest.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/MediaRangeList.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/MediaRangeList.java?rev=1541131&r1=1541130&r2=1541131&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/MediaRangeList.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/MediaRangeList.java
Tue Nov 12 16:30:16 2013
@@ -235,7 +235,12 @@ public class MediaRangeList extends Tree
 
         private void setType(String typeDef) {
             String[] parts = typeDef.split("/");
-            this.setType(parts[0], parts[1]);
+            String superType = parts[0];
+            String subType = WILDCARD;
+            if(parts.length > 1){
+                subType = parts[1];
+            }
+            this.setType(superType,subType);
         }
 
         MediaRange(String supertype, String subtype, double q) {

Modified: sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/MediaRangeListTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/MediaRangeListTest.java?rev=1541131&r1=1541130&r2=1541131&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/MediaRangeListTest.java
(original)
+++ sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/MediaRangeListTest.java
Tue Nov 12 16:30:16 2013
@@ -63,4 +63,23 @@ public class MediaRangeListTest extends 
         assertTrue("Did not contain media type from query param", rangeList.contains("text/html"));
         assertFalse("Contained media type from overridden Accept header", rangeList.contains("text/plain"));
     }
+
+    public void testInvalidJdkAcceptHeader() {
+        //This header is sent by Java client which make use of URLConnection on Oracle JDK
+        //See acceptHeader at http://hg.openjdk.java.net/jdk6/jdk6-gate/jdk/file/tip/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
+        //To support such case the MediaRange parser has to be made bit linient
+        final String invalidHeader = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
+        MockSlingHttpServletRequest req = new MockSlingHttpServletRequest(null, null, null,
null, null) {
+            @Override
+            public String getHeader(String name) {
+                return name.equals(MediaRangeList.HEADER_ACCEPT) ? invalidHeader : super.getHeader(name);
+            }
+
+            public <AdapterType> AdapterType adaptTo(Class<AdapterType> type)
{
+                return null;
+            }
+        };
+        MediaRangeList rangeList = new MediaRangeList(req);
+        assertTrue("Did not contain media type from query param", rangeList.contains("text/html"));
+    }
 }



Mime
View raw message