Fixed bug where POST on "Content-Type: application/sparql-query; charset=UTF-8" did not work
authorHenry Story <henry.story@bblfish.net>
Fri, 01 Jun 2012 22:59:50 +0200
changeset 225 a6bbafc980cb
parent 224 eb0d323ef2a6
child 226 21cbae5c990c
Fixed bug where POST on "Content-Type: application/sparql-query; charset=UTF-8" did not work
src/main/scala/Post.scala
src/main/scala/ReadWriteWeb.scala
--- a/src/main/scala/Post.scala	Fri Jun 01 22:54:08 2012 +0200
+++ b/src/main/scala/Post.scala	Fri Jun 01 22:59:50 2012 +0200
@@ -27,6 +27,11 @@
   val supportContentTypes = Lang.supportContentTypes ++ Image.supportedImages.map(_.contentType) + SPARQL
   val supportedAsString = supportContentTypes mkString ", "
 
+  def supportsContentType(contentTypeHeader: String) = {
+    supportContentTypes.contains(cleanHeader(contentTypeHeader))
+  }
+
+  def cleanHeader(headerVal: String) = headerVal.split(";")(0).trim
   
   val logger: Logger = LoggerFactory.getLogger(this.getClass)
 
@@ -34,7 +39,7 @@
       is: InputStream,
       base: URL,
       contentType: String): Post = {
-    assert(supportContentTypes contains contentType)
+    assert(supportsContentType(contentType))
 
     val inAsString = {
        val source = Source.fromInputStream(is, "UTF-8")
@@ -61,7 +66,7 @@
       }
 
     
-    contentType match {
+    cleanHeader(contentType) match {
       case SPARQL => postUpdate | (postQuery | PostUnknown)
       case RequestLang(lang) => postRDF(lang) | PostUnknown
       case GIF.contentType | JPEG.contentType | PNG.contentType => PostBinary(is)
--- a/src/main/scala/ReadWriteWeb.scala	Fri Jun 01 22:54:08 2012 +0200
+++ b/src/main/scala/ReadWriteWeb.scala	Fri Jun 01 22:59:50 2012 +0200
@@ -149,7 +149,7 @@
                   }
                 }
               }
-            case POST(_) & RequestContentType(ct) if Post.supportContentTypes contains ct => {
+            case POST(_) & RequestContentType(ct) if Post.supportsContentType(ct) => {
               Post.parse(Body.stream(req), uri, ct) match {
                 case PostUnknown => {
                   logger.info("Couldn't parse the request")