mime types followed by charset types would break the mime type recognition and select rdfxml webid
authorHenry Story <henry.story@bblfish.net>
Wed, 21 Dec 2011 23:06:27 +0100
branchwebid
changeset 159 55785ff6ed2f
parent 158 81652221976f
child 160 7b456ecbce47
mime types followed by charset types would break the mime type recognition and select rdfxml
src/main/scala/Lang.scala
src/main/scala/WebCache.scala
src/main/scala/util/SpyInputStream.scala
--- a/src/main/scala/Lang.scala	Wed Dec 21 16:49:45 2011 +0100
+++ b/src/main/scala/Lang.scala	Wed Dec 21 23:06:27 2011 +0100
@@ -54,7 +54,7 @@
   val default = RDFXML
   
   def apply(contentType: String): Option[Lang] =
-    contentType match {
+    contentType.trim.toLowerCase match {
       case "text/n3" => Some(N3)
       case "text/turtle" => Some(TURTLE)
       case "application/rdf+xml" => Some(RDFXML)
--- a/src/main/scala/WebCache.scala	Wed Dec 21 16:49:45 2011 +0100
+++ b/src/main/scala/WebCache.scala	Wed Dec 21 23:06:27 2011 +0100
@@ -28,10 +28,10 @@
 import org.w3.readwriteweb.util._
 import java.net.{ConnectException, URL}
 import scalaz.{Scalaz, Validation}
-import java.io.File
 import java.util.concurrent.TimeUnit
 import com.google.common.cache.{CacheLoader, CacheBuilder, Cache}
 import org.w3.readwriteweb.Lang._
+import java.io.{FileOutputStream, File}
 
 
 /**
@@ -85,7 +85,9 @@
       val handler: Handler[Validation[Throwable, Model]] = request.>+>[Validation[Throwable, Model]](res =>  {
         res >:> { headers =>
           val encoding = headers("Content-Type").headOption match {
-            case Some(mime) => Lang(mime) getOrElse Lang.default
+            case Some(mime) => {
+              Lang(mime.split(";")(0)) getOrElse Lang.default
+            }
             case None => RDFXML  //todo: it would be better to try to do a bit of guessing in this case by looking at content
           }
           val loc = headers("Content-Location").headOption match {
--- a/src/main/scala/util/SpyInputStream.scala	Wed Dec 21 16:49:45 2011 +0100
+++ b/src/main/scala/util/SpyInputStream.scala	Wed Dec 21 23:06:27 2011 +0100
@@ -41,6 +41,7 @@
        in.read()
    } catch {
       case ioe: IOException => {
+        out.flush()
         out.close()
         stopOut=true
         throw ioe;