Fixed the lack of ability to set the RDF base URI. This is a huge kludge. The incoming HTTP request URI is parsed relative to this, so no path components of the base have any effect. Allows me to use --base http://localhost/ when used as proxy on a different port, though. Also a kludge as sets and reads a system variable, would be great for someone to fix it so it is passed through as a paremeter.
authorTim Berners-Lee <timbl+hg@w3.org>
Mon, 04 Jun 2012 16:05:57 -0400
changeset 228 dea36790ed17
parent 227 179151ae16b0
child 229 fae877adc4d2
Fixed the lack of ability to set the RDF base URI. This is a huge kludge. The incoming HTTP request URI is parsed relative to this, so no path components of the base have any effect. Allows me to use --base http://localhost/ when used as proxy on a different port, though. Also a kludge as sets and reads a system variable, would be great for someone to fix it so it is passed through as a paremeter.
src/main/scala/Authoritative.scala
src/main/scala/ReadWriteWebArgs.scala
--- a/src/main/scala/Authoritative.scala	Fri Jun 01 23:52:34 2012 +0200
+++ b/src/main/scala/Authoritative.scala	Mon Jun 04 16:05:57 2012 -0400
@@ -35,7 +35,9 @@
   val r = """^(.*)\.(\w{0,4})$""".r
 
   // all of this would be unnecessary if req.uri would really return the full URI
-  // we should try to push for that to be done at unfiltered layer
+  // we should try to push for that to be done at unfiltered layer - HS
+  // Alternatively, build the system to not need to know, or be told, its base hostport. - TBL
+  //
   def reqURL[T](m: Manifest[T], r: HttpRequest[T]): String = {
     if (m <:< manifest[HttpServletRequest]) reqUrlServlet(r.asInstanceOf[HttpRequest[HttpServletRequest]])
     else if (m <:< manifest[ReceivedMessage]) reqUrlNetty(r.asInstanceOf[HttpRequest[ReceivedMessage]])
@@ -43,13 +45,20 @@
   }
 
   def unapply[T](req: HttpRequest[T]) (implicit m: Manifest[T]) : Option[(URL, Representation)] =  {
+
+    val uriBase: Option[String] = Option(System getProperty "rww.uriBase") // @@ Hack
+
     val uri = reqURL(m, req)
     val suffixOpt = uri match {
       case r(_, suffix) => Some(suffix)
       case _ if uri endsWith "/" => Some("/")
       case _ => None
     }
-    Some((new URL(uri), Representation(suffixOpt, Accept(req))))
+
+    uriBase match {
+        case Some(base) => Some((new URL(new URL(base), req.uri), Representation(suffixOpt, Accept(req))))        
+        case None =>  Some((new URL(uri), Representation(suffixOpt, Accept(req))))
+    }
   }
 
 
--- a/src/main/scala/ReadWriteWebArgs.scala	Fri Jun 01 23:52:34 2012 +0200
+++ b/src/main/scala/ReadWriteWebArgs.scala	Mon Jun 04 16:05:57 2012 -0400
@@ -180,6 +180,10 @@
   val httpPort = parser.option[Int]("http", "port","start the http server on port")
   val httpsPort = parser.option[Int]("https","port","start the https server on port")
 
+  val uriBase = parser.option[String]("base","uri","base URI for processing RDF") {
+    (sValue, opt) => System.setProperty("rww.uriBase", sValue)
+  }
+
   val rootDirectory = parser.parameter[File]("rootDirectory", "path to root directory where files are served", false) {
     (sValue, opt) => {
       val file = new File(sValue)