incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r603526 - /incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Date Wed, 12 Dec 2007 09:47:30 GMT
Author: bdelacretaz
Date: Wed Dec 12 01:47:29 2007
New Revision: 603526

URL: http://svn.apache.org/viewvc?rev=603526&view=rev
Log:
SLING-135, make content-type selection more robust in DefaultSlingServlet

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=603526&r1=603525&r2=603526&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Wed Dec 12 01:47:29 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.microsling.slingservlets;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -138,12 +139,33 @@
     {
         postServlet.service(request, response);
     }
+    
+    /** SLING-135, find Content-Type for given URL, in a safe way 
+     *  TODO: use the MimeTypeService from sling-commons?
+     * */
+    protected String getContentType(URL url) {
+        String result = null;
+        
+        // get the filename from the URL
+        String filename = url.getPath();
+        filename = new File(filename).getName();
+        
+        // get content-type, avoid null
+        // previously used conn.getContentType(), but see SLING-112
+        if(filename!=null) {
+            result = getServletContext().getMimeType(filename);
+        }
+        if(result==null) {
+            result = "application/octet-stream";
+        }
+        
+        return result;
+    }
 
     protected void spool(URL url, SlingHttpServletResponse res) throws IOException {
         URLConnection conn = url.openConnection();
 
-        // this previously used conn.getContentType(), but see SLING-112
-        res.setContentType(getServletContext().getMimeType(url.getFile()));
+        res.setContentType(getContentType(url));
         if (conn.getContentLength() > 0 ) {
             res.setContentLength(conn.getContentLength());
         }



Mime
View raw message